diff --git a/src/runtime/Builder.js b/src/runtime/Builder.js index f81f43e..01e8507 100644 --- a/src/runtime/Builder.js +++ b/src/runtime/Builder.js @@ -18,6 +18,7 @@ import perf from './builders/widgets/Performance/build' import spinner from './builders/widgets/Spinner/build' import model from './builders/widgets/Model/build' import widget from './builders/widgets/Widget/build' +import javascript from './builders/widgets/Javascript/build' import api from './builders/api/build' @@ -56,6 +57,7 @@ class Builder { spinner(), toggle(), model(), + javascript(), api(), diff --git a/src/runtime/builders/application/init/init.js b/src/runtime/builders/application/init/init.js index 5e58baf..539cd1e 100644 --- a/src/runtime/builders/application/init/init.js +++ b/src/runtime/builders/application/init/init.js @@ -4,6 +4,7 @@ /* global models */ /* global animateFps */ /* global spinner */ +/* global javascript */ function init() { createjs.Ticker.framerate = animateFps @@ -16,11 +17,15 @@ function init() { initWidgets() ]).then(() => { resolveValueProviders() - Object.entries(models).forEach(([id, model]) => model.init()) - Object.entries(widgets).forEach(([id, widget]) => widget.updateComponent()) + Object.entries(models).forEach(([, model]) => model.init()) + + javascript.onBeforeModelRun.forEach(fn => fn()) + + Object.entries(models).forEach(([, model]) => model.play()) + Object.entries(widgets).forEach(([, widget]) => widget.updateComponent()) spinner.hide() }) }) } -export default init \ No newline at end of file +export default init diff --git a/src/runtime/builders/widgets/Javascript/build.js b/src/runtime/builders/widgets/Javascript/build.js new file mode 100644 index 0000000..cddaa29 --- /dev/null +++ b/src/runtime/builders/widgets/Javascript/build.js @@ -0,0 +1,10 @@ +import configuration from './configuration' +import generateTemplate from '@runtime/builders/generateTemplate' + +export default () => { + const script = `const javascript = ${generateTemplate(configuration())}` + const html = '' + const css = '' + + return { script, html, css } +} diff --git a/src/runtime/builders/widgets/Javascript/configuration.js b/src/runtime/builders/widgets/Javascript/configuration.js new file mode 100644 index 0000000..357a0a9 --- /dev/null +++ b/src/runtime/builders/widgets/Javascript/configuration.js @@ -0,0 +1,17 @@ +import configureStore from '@src/configureStore' +import { getJavascripts } from '@reducers' + +export default () => { + const store = configureStore().store.getState() + + let javascript = { + onBeforeModelRun: [] + } + + Object.entries(getJavascripts(store)).forEach(([, item]) => { + const fn = `function() {${item.javascript}}` + javascript.onBeforeModelRun.push(new Function(`return ${fn}`)()) + }) + + return javascript +} diff --git a/src/runtime/builders/widgets/Model/template/init.js b/src/runtime/builders/widgets/Model/template/init.js index aab6ffd..e4d52f3 100644 --- a/src/runtime/builders/widgets/Model/template/init.js +++ b/src/runtime/builders/widgets/Model/template/init.js @@ -3,5 +3,4 @@ export default function init() { this.instantiate() this.setup() - this.play() -} \ No newline at end of file +}