Skip to content

Instantly share code, notes, and snippets.

@mariusandra
Last active June 13, 2019 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariusandra/770901945874dacd4fea3ab4cdf9b7d5 to your computer and use it in GitHub Desktop.
Save mariusandra/770901945874dacd4fea3ab4cdf9b7d5 to your computer and use it in GitHub Desktop.
// Plugin to make preloaded state work with kea 1.0
// (pseudocode, not tested, use )
{
name: 'preloadedState',
buildSteps: {
defaults (logic, input) {
const node = getContext().options.preloadedState
if (node) {
// find preLoadedState.[path[0]].[path[1]].etc
for (const pathStep of logic.path) {
if (node[pathStep]) {
node = node[pathStep]
} else {
return
}
}
// set as defaults
if (typeof node !== 'undefined') {
Object.assign(logic.defaults, node)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment