|
|
@ -8,6 +8,7 @@ import { createTreeNode } from "../render/prepareRenderComponent" |
|
|
import { getState } from "./getState" |
|
|
import { getState } from "./getState" |
|
|
import { attachChildren } from "../render/attachChildren" |
|
|
import { attachChildren } from "../render/attachChildren" |
|
|
import mustache from "mustache" |
|
|
import mustache from "mustache" |
|
|
|
|
|
import { appStore } from "./store"; |
|
|
|
|
|
|
|
|
import { parseBinding } from "./parseBinding" |
|
|
import { parseBinding } from "./parseBinding" |
|
|
|
|
|
|
|
|
@ -24,14 +25,14 @@ const isMetaProp = propName => |
|
|
propName === "_styles" |
|
|
propName === "_styles" |
|
|
|
|
|
|
|
|
export const createStateManager = ({ |
|
|
export const createStateManager = ({ |
|
|
store, |
|
|
// store,
|
|
|
appRootPath, |
|
|
appRootPath, |
|
|
frontendDefinition, |
|
|
frontendDefinition, |
|
|
componentLibraries, |
|
|
componentLibraries, |
|
|
onScreenSlotRendered, |
|
|
onScreenSlotRendered, |
|
|
routeTo, |
|
|
routeTo, |
|
|
}) => { |
|
|
}) => { |
|
|
let handlerTypes = eventHandlers(store, appRootPath, routeTo) |
|
|
let handlerTypes = eventHandlers(appStore, appRootPath, routeTo) |
|
|
let currentState |
|
|
let currentState |
|
|
|
|
|
|
|
|
// any nodes that have props that are bound to the store
|
|
|
// any nodes that have props that are bound to the store
|
|
|
@ -45,33 +46,40 @@ export const createStateManager = ({ |
|
|
// nodesBoundByProps,
|
|
|
// nodesBoundByProps,
|
|
|
// nodesWithCodeBoundChildren
|
|
|
// nodesWithCodeBoundChildren
|
|
|
// )
|
|
|
// )
|
|
|
|
|
|
|
|
|
const bb = bbFactory({ |
|
|
const bb = bbFactory({ |
|
|
store, |
|
|
store: appStore, |
|
|
getCurrentState, |
|
|
getCurrentState, |
|
|
frontendDefinition, |
|
|
frontendDefinition, |
|
|
componentLibraries, |
|
|
componentLibraries, |
|
|
onScreenSlotRendered, |
|
|
onScreenSlotRendered, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
const setup = _setup(handlerTypes, getCurrentState, bb) |
|
|
const setup = _setup({ handlerTypes, getCurrentState, bb, store: appStore }) |
|
|
|
|
|
|
|
|
|
|
|
// TODO: remove
|
|
|
|
|
|
const unsubscribe = appStore.subscribe(state => { |
|
|
|
|
|
console.log("store updated", state); |
|
|
|
|
|
return state; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const unsubscribe = store.subscribe( |
|
|
// const unsubscribe = store.subscribe(
|
|
|
onStoreStateUpdated({ |
|
|
// onStoreStateUpdated({
|
|
|
setCurrentState: state => (currentState = state), |
|
|
// setCurrentState: state => (currentState = state),
|
|
|
getCurrentState, |
|
|
// getCurrentState,
|
|
|
// nodesWithCodeBoundChildren,
|
|
|
// // nodesWithCodeBoundChildren,
|
|
|
// nodesBoundByProps,
|
|
|
// // nodesBoundByProps,
|
|
|
componentLibraries, |
|
|
// componentLibraries,
|
|
|
onScreenSlotRendered, |
|
|
// onScreenSlotRendered,
|
|
|
setupState: setup, |
|
|
// setupState: setup,
|
|
|
}) |
|
|
// })
|
|
|
) |
|
|
// )
|
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
setup, |
|
|
setup, |
|
|
destroy: () => unsubscribe(), |
|
|
destroy: () => unsubscribe(), |
|
|
getCurrentState, |
|
|
getCurrentState, |
|
|
store, |
|
|
store: appStore, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -80,16 +88,19 @@ const onStoreStateUpdated = ({ |
|
|
getCurrentState, |
|
|
getCurrentState, |
|
|
componentLibraries, |
|
|
componentLibraries, |
|
|
onScreenSlotRendered, |
|
|
onScreenSlotRendered, |
|
|
setupState, |
|
|
setupState |
|
|
}) => state => { |
|
|
}) => state => { |
|
|
setCurrentState(state) |
|
|
// fire the state update event to re-render anything bound to this
|
|
|
attachChildren({ |
|
|
// setCurrentState(state)
|
|
|
componentLibraries, |
|
|
|
|
|
treeNode: createTreeNode(), |
|
|
// setCurrentState(state)
|
|
|
onScreenSlotRendered, |
|
|
// attachChildren({
|
|
|
setupState, |
|
|
// componentLibraries,
|
|
|
getCurrentState, |
|
|
// treeNode: createTreeNode(),
|
|
|
})(document.querySelector("#app"), { hydrate: true, force: true }) |
|
|
// onScreenSlotRendered,
|
|
|
|
|
|
// setupState,
|
|
|
|
|
|
// getCurrentState,
|
|
|
|
|
|
// })(document.querySelector("#app"), { hydrate: true, force: true })
|
|
|
|
|
|
|
|
|
// // the original array gets changed by components' destroy()
|
|
|
// // the original array gets changed by components' destroy()
|
|
|
// // so we make a clone and check if they are still in the original
|
|
|
// // so we make a clone and check if they are still in the original
|
|
|
@ -154,32 +165,41 @@ const onStoreStateUpdated = ({ |
|
|
// node.component.$set(newProps)
|
|
|
// node.component.$set(newProps)
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
const _setup = ( |
|
|
const _setup = ({ |
|
|
handlerTypes, |
|
|
handlerTypes, |
|
|
getCurrentState, |
|
|
getCurrentState, |
|
|
bb |
|
|
bb, |
|
|
) => node => { |
|
|
store |
|
|
|
|
|
}) => node => { |
|
|
console.log(node); |
|
|
|
|
|
const props = node.props |
|
|
const props = node.props |
|
|
const context = node.context || {} |
|
|
const context = node.context || {} |
|
|
const initialProps = { ...props } |
|
|
const initialProps = { ...props } |
|
|
// const storeBoundProps = []
|
|
|
// const storeBoundProps = []
|
|
|
const currentStoreState = getCurrentState() |
|
|
const currentStoreState = getCurrentState() |
|
|
|
|
|
|
|
|
|
|
|
console.log("node", node); |
|
|
|
|
|
|
|
|
|
|
|
// console.log("node", node);
|
|
|
|
|
|
// console.log("nodeComponent", node.component);
|
|
|
|
|
|
|
|
|
for (let propName in props) { |
|
|
for (let propName in props) { |
|
|
if (isMetaProp(propName)) continue |
|
|
if (isMetaProp(propName)) continue |
|
|
|
|
|
|
|
|
const propValue = props[propName] |
|
|
const propValue = props[propName] |
|
|
|
|
|
|
|
|
// const binding = parseBinding(propValue)
|
|
|
// const binding = parseBinding(propValue)
|
|
|
// const isBound = !!binding
|
|
|
// TODO: better binding stuff
|
|
|
|
|
|
const isBound = typeof propValue === "string" && propValue.startsWith("{{"); |
|
|
|
|
|
|
|
|
if (typeof propValue === "string") { |
|
|
if (isBound) { |
|
|
initialProps[propName] = mustache.render(propValue, { |
|
|
initialProps[propName] = mustache.render(propValue, { |
|
|
state: currentStoreState, |
|
|
state: currentStoreState, |
|
|
context |
|
|
context |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if (!node.stateBound) { |
|
|
|
|
|
node.stateBound = true |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// if (isBound) binding.propName = propName
|
|
|
// if (isBound) binding.propName = propName
|
|
|
@ -254,7 +274,7 @@ const _setup = ( |
|
|
|
|
|
|
|
|
// registerBindings(node, storeBoundProps)
|
|
|
// registerBindings(node, storeBoundProps)
|
|
|
|
|
|
|
|
|
const setup = _setup(handlerTypes, getCurrentState, bb) |
|
|
const setup = _setup({ handlerTypes, getCurrentState, bb, store }) |
|
|
initialProps._bb = bb(node, setup) |
|
|
initialProps._bb = bb(node, setup) |
|
|
|
|
|
|
|
|
return initialProps |
|
|
return initialProps |
|
|
|