-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new declareStore factory #15
Conversation
Pull Request Test Coverage Report for Build 4065603664
💛 - Coveralls |
@chartyom First of all, thank you for the contribution! Please consider the following points, because the proposed changes don't align with the library:
I'd like to propose you to remake existed
|
|
||
const localStore = createLocalStore( | ||
{ userId: 1 }, | ||
{ comparator: (prevState, nextState) => prevState === nextState }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the custom comparator should be different from the base comparator to test properly that the custom on is used by the store.
( | ||
initialState?: State | StateMutation<State> | null, | ||
options?: StoreOptions<State>, | ||
): Store<State> & StoreWithUpdates<State, CaseUpdates>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StoreWithUpdates<State, CaseUpdates>
is enough here.
): Store<State> & StoreWithUpdates<State, CaseUpdates>; | |
): StoreWithUpdates<State, CaseUpdates>; |
StoreWithUpdates, | ||
} from './store'; | ||
|
||
interface StoreOptions<State> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the original StoreOptions
from store.ts
to allow changing name
for a specific store instance.
const { initialState, updates, name, comparator } = props; | ||
|
||
const _state = | ||
typeof initialState === 'function' ? initialState() : initialState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialState()
factory should be called only during creation of an actual store instance
const _store = createStore<State>(_initialState, { | ||
comparator: options?.comparator ?? comparator, | ||
name, | ||
onDestroy: options?.onDestroy, | ||
}); | ||
|
||
return { | ||
..._store, | ||
updates: createStoreUpdates(_store.update, updates), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reuse a code from declareStoreWithUpdates()
:
return withStoreUpdates<State, Updates>(
createStore<State>(state, { ...baseOptions, ...options }),
updates,
);
onDestroy?: () => void; | ||
} | ||
|
||
interface StoreProps< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface StoreProps< | |
type DeclareStoreOptions<...> = Readonly<{ ... }> |
name?: Name; | ||
|
||
initialState: InitialState; | ||
|
||
updates: Updates; | ||
/** A comparator for detecting changes between old and new states */ | ||
comparator?: (prevState: State, nextState: State) => boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider to align with options of declareStoreWithUpdates()
. I suggest:
initialState: InitialState,
updates: Updates,
options?: StoreOptions<State>,
Thank you for the PR. I consider to use |
I prepared a new syntax for declare store. What do you think?
before
after