Last active
March 14, 2019 10:46
-
-
Save arturovt/fde8f6f6d31f4f2e616cfbcf8a00757d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const META_KEY = 'NGXS_META'; | |
function State(options) { | |
return (target) => { | |
const meta = ensureStoreMetadata(target); | |
// Handle inheritance | |
if (Object.getPrototypeOf(target).hasOwnProperty(META_KEY)) { | |
const parentMeta = Object.getPrototypeOf(target)[META_KEY]; | |
meta.actions = Object.assign({}, meta.actions, parentMeta.actions); | |
} | |
meta.children = options.children; | |
meta.defaults = options.defaults; | |
meta.name = options.name; | |
if (!options.name) { | |
throw new Error(`States must register a 'name' property`); | |
} | |
if (!stateNameRegex.test(options.name)) { | |
throw new Error(stateNameErrorMessage(options.name)); | |
} | |
}; | |
} | |
@State({ | |
name: 'todos', | |
defaults: [] | |
}) | |
class TodosState {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment