Closed sinster2003 closed 9 months ago
@lindelwa122 I will start working on getStore
function if any improvements needed feel free.
Hey, @sinster2003, I appreciate your implementation. Please make the following improvements before I can accept your PR:
_store
are not exposed. Users should be able to access the store only through public methods like getState()
.createStore
as many times as they need? If the store already exists, the function should then add new variables to the store and overwrite existing ones with the same names. What are your thoughts on this change?Hey @lindelwa122 I have figured out the changes that can be made ...
createStore
is used to just create store, the store won't be exposed the user can only retrieve the store for update and getState only using getStore()this
pointer in both getState and updateState we need an object reference of store. Something like this:
createStore(store);
const data = getStore(); // gets the store from anywhere
console.log(data); // retrives store
console.log(data.getState("name")); // gets the property
const newdata = data.updateState("name", "akash"); // updates the state of store
console.log("New data", newdata); // new updated state
I think your previous thought process of createStore
was absolutely right making it invokable only once and i feel that implementation is better than overwriting the store again and again, conceptually it doesn't sound good. If i give overwriting as the primary feature I just feel the importance of updateState
will decrease multifolds. So we will proceed with the previous approach. I tested the changed code and it did work.
If changes needed do feel free.
I will resolve the branch conflicts and make a PR
Hi @lindelwa122 , so I have worked on this issue, the approach goes as follows:
localStorage
to store the object passed by the userupdateState
getState
so that the store can use it.getStore
function has to be created so that user can retrieve it from anywhere that object returned will containsvariables
,getState
,updateState
I will take up this issue after createStoreGo through the documentation once