{"code":"export class MagicValue {\r\n    constructor(config, controller, keyName, val) {\r\n        this.config = config;\r\n        this.controller = controller;\r\n        this.keyName = keyName;\r\n        this.val = val;\r\n    }\r\n    startTask() {\r\n        this.pending = true;\r\n        this.runningTimeout = setTimeout(() => (this.spinning = true), this.config.spinnerTimeout || 2000);\r\n    }\r\n    finishTask() {\r\n        if (this.runningTimeout)\r\n            clearTimeout(this.runningTimeout);\r\n        this.pending = false;\r\n        this.spinning = false;\r\n    }\r\n    pull() {\r\n        this.startTask();\r\n        return this.controller\r\n            .get(this.keyName)\r\n            .then(fetchedVal => {\r\n            this.val = fetchedVal;\r\n            this.finishTask();\r\n            return fetchedVal;\r\n        })\r\n            .catch(err => {\r\n            console.error(err);\r\n            this.error = err;\r\n            this.finishTask();\r\n        });\r\n    }\r\n    push() {\r\n        if (this.config.pendingOnPush !== false)\r\n            this.startTask();\r\n        return this.controller\r\n            .set(this.keyName, this.val)\r\n            .then(() => this.finishTask())\r\n            .catch(err => {\r\n            console.error(err);\r\n            this.error = err;\r\n            this.finishTask;\r\n        });\r\n    }\r\n}\r\nexport class Magic {\r\n    constructor(config) {\r\n        let modulesConfig = config.modules || {};\r\n        for (let moduleName of Object.keys(modulesConfig)) {\r\n            let module = modulesConfig[moduleName];\r\n            if (!module.data) {\r\n                throw new Error(`Module \"${moduleName}\" has no configured data`);\r\n            }\r\n            if (!module.controller) {\r\n                throw new Error(`Module \"${moduleName}\" has no configurred controller`);\r\n            }\r\n            this[moduleName] = {};\r\n            for (let key of Object.keys(module.data)) {\r\n                this[moduleName][key] = new MagicValue(config, module.controller, key, module.data[key]);\r\n                this[moduleName][key].pull();\r\n            }\r\n        }\r\n    }\r\n}\r\n","map":{"mappings":""}}
