Skip to content

Commit

Permalink
build: v0.3.22
Browse files Browse the repository at this point in the history
adds `getState()` in slice
  • Loading branch information
kennyfrc committed May 27, 2024
1 parent ba658f6 commit d216fba
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

⚠️ Expect API changes until v1.0.0 ⚠️

Current version: 0.3.21.
Current version: 0.3.22.

Bundle Size: 14kb minified & gzipped.

Expand Down
4 changes: 2 additions & 2 deletions build/cami.cdn.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/cami.cdn.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/cami.module.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/cami.module.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/javascripts/cami.cdn.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/javascripts/cami.cdn.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cami",
"version": "0.3.21",
"version": "0.3.22",
"author": "Kenn Costales <[email protected]>",
"repository": {
"type": "git",
Expand Down
9 changes: 7 additions & 2 deletions src/observables/observable-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ class ObservableStore extends Observable {
* @param {string} options.name - The name of the slice.
* @param {Object} options.state - The initial state of the slice.
* @param {Object} options.actions - The actions for the slice.
* @returns {Object} - An object containing the action methods for the slice.
* @returns {Object} - An object containing the action methods for the slice, including a getState method.
*
* @example
* const cartSlice = slice(appStore, {
Expand All @@ -568,6 +568,7 @@ class ObservableStore extends Observable {
*
* cartSlice.add({ name: 'Product 1', price: 100 });
* cartSlice.remove({ id: 123456789 });
* console.log(cartSlice.getState()); // Logs the current state of the cart slice
*/
const slice = (store, { name, state, actions }) => {
if (store.slices && store.slices[name]) {
Expand Down Expand Up @@ -610,7 +611,11 @@ const slice = (store, { name, state, actions }) => {
sliceSubscribers.forEach(callback => callback(sliceState));
});

return { ...sliceActions, subscribe };
const getState = () => {
return store.state[name];
};

return { ...sliceActions, subscribe, getState };
};

/**
Expand Down

0 comments on commit d216fba

Please sign in to comment.