Last active
June 13, 2019 07:29
-
-
Save mariusandra/770901945874dacd4fea3ab4cdf9b7d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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