Skip to content

Instantly share code, notes, and snippets.

@arturovt
Last active March 14, 2019 10:46
Show Gist options
  • Save arturovt/fde8f6f6d31f4f2e616cfbcf8a00757d to your computer and use it in GitHub Desktop.
Save arturovt/fde8f6f6d31f4f2e616cfbcf8a00757d to your computer and use it in GitHub Desktop.
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