summaryrefslogtreecommitdiff
path: root/lib.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib.js')
-rw-r--r--lib.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib.js b/lib.js
new file mode 100644
index 0000000..b529085
--- /dev/null
+++ b/lib.js
@@ -0,0 +1,31 @@
+const Lib = {
+ makeStateContainer(intialState, renderCallback) {
+ let currentState = intialState
+ return {
+ set(newState, afterRenderCallback = () => {}) {
+ currentState = { ...currentState, ...newState }
+ renderCallback()
+ afterRenderCallback()
+ },
+ get() { return currentState }
+ }
+ },
+ splitAt(str, index) {
+ return [str.slice(0, index), str.slice(index)]
+ },
+ readFile(file) {
+ return new Promise(function(resolve, reject) {
+ const reader = new FileReader()
+ reader.onload = function(event) {
+ resolve(event.target.result)
+ }
+ reader.readAsText(file)
+ })
+ },
+ getQueryParam(paramName) {
+ const queryPairs = window.location.search.slice(1).split("&").map(k => k.split("="))
+ const foundPair = queryPairs.find(([name]) => name === paramName)
+ if(!foundPair) return null;
+ return foundPair[1]
+ }
+}