-
Notifications
You must be signed in to change notification settings - Fork 3
Store
Matheus Marsiglio edited this page Aug 20, 2018
·
1 revision
The Store is where your data is structure following an object structure like its contracts.
Store creation example:
// NucleoObjectTypes declarations to create their contracts
const completeNameType = new NucleoObjectType({
name: 'completeName',
fields: {
firstName: NucleoString,
lastName: NucleoString
}
});
const userTestType = new NucleoObjectType({
name: 'userTest',
fields: {
name: completeNameType,
age: NucleoNumber
}
});
const productsTestType = new NucleoObjectType({
name: 'productTest',
fields: {
available: NucleoBoolean
}
});
// the contracts model to be passed to the store creation
const contracts = {
userTest: userTestType,
productsTest: productsTestType
};
// store creation
const newStore = createStore(contracts); // returns an object with dispatch, getStore and subscribe
Now inside newStore
we have dispatch. If you try to dispatch
data to its place in store (and do it following the contracts when you created it):
const { dispatch } = newStore;
// dispatching data to userTest
dispatch('userTest')({
name: { firstName: 'John', lastName: 'Doe' },
age: 30
});
and you use getStore
function to visualize how your store looks like:
const { getStore } = newStore;
console.log(getStore()); // { userTest: { name: { firstName: 'John', lastName: 'Doe' }, age: 30 } }