Closed mh-alahdadian closed 4 years ago
@MHA15 I do not understand very well that what you do not like and what is your proposal. Can you give an example of how you would like the API to be?
The purpose of Garfio
is to capture patterns that are used in other libraries and re-implement it on top of Hookleton
so that anyone improves even if it implies the change in the API is welcome. We have not yet reached version 1.0.0 :-)
Can you give an example of how you would like the API to be?
for example
createStore(hook, ...initial?): Store<T>;
useStore(store, ...initial?): T
interface Store<T> {
get(): T;
destroy(): void;
}
Ah, I see.
The current API of garfio/store
is more general. The store identifier can be anything choose by user. Say a string, a Symbol, a object, a uuid string, ... The uniqueness of id is left to the user.
You example API can be recreate easely in top of the current API:
Ex:
import { createStore as _createStore, useStore as _useStore, getStore, removeStore } from 'garfio/store';
export function createStore(hook, ...initial) {
const id = Symbol();
_createStore(id, hook, ...initial);
return { id, get: () => getStore(id), destroy: () => removeStore(id) }
}
export function useStore({ id }, ...initial) {
return _useStore(id, ...initial);
}
I am not sure if these types of cases that are more specific should be added to the module. Or just point them out as a pattern in the Doc
Actually the store
is a Map in the store.js
module: https://github.com/bySabi/garfio/blob/master/src/store.js#L3. Which becomes global thanks to the fact that node
imports each module only once, per app, regardless of all the sites where it is required
Or even more simple with:
import { createStore as _createStore, getStore, removeStore } from 'garfio/store';
export function createStore(hook, ...initial) {
const store = {}
_createStore(store, hook, ...initial);
store.get = () => getStore(store);
store.destroy = () => removeStore(store)
return store;
}
It is quite likely that you will use this API in the next version, 0.2.0
. It is much simpler and functional.
Thanks for suggesting it.
Hey @MHA15 I add your suggested changes to Store API We will let typescript for 2020 Happy new year!!
I had like store functions very much but I don't want to name my stores and worrying about unique key for them I think that it might be a good idea that
createStore
can return a store object which have.get
method and module can have another function foruseStore
which will received store as params I think that this type of store might not be compatible with already version of it so you can find another name for itThanks