-
Notifications
You must be signed in to change notification settings - Fork 12
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
Make "DeepImmutable" optional. #58
Comments
Hi @LouizFC, There is also another open issue on #55 that I think share the same cause. @rlesniak @Haaxor1689 It would be great to have you guys on this to make a good decision. I'm confused about import { createActionCreator, createReducer, DeepImmutable } from 'deox'
type RootState = DeepImmutable<{ counter: number }>
const increment = createActionCreator('INCREMENT')
const handleIncrement = (state: RootState) => ({ ...state, count: state.count + 1 })
const defaultState: RootState = { counter: 0 }
const rootReducer = createReducer(defaultState, handleAction => [
handleAction(increment, handleIncrement)
]) |
Your export interface HttpUriStore {
readonly rawUrl: string;
readonly query: Param[];
readonly method: string;
} And Making the |
@Haaxor1689 all my functions are pure, I just forgot to make the return type explicit. While I understand that DeepImmutable gives you extra safety and enforces redux philosophy, I do not want to "spread" all these types on my projects just so I can use the utility that deox provides I really enjoy using deox, but I think that "managing immutability" should be an optional part of this lib, not something that should be forced to the user. For example, in this project I am using immer to manage my immutable state, so I don't need the extra layer that deox provides. |
@LouizFC I confirm, with the exception of arrays. I need to type the draft type explicitly when using array specific methods. // no need to specify type
handle(actions.updateParam, (state, { payload }) =>
produce(state, (draft) => {
draft[payload.index] = payload.param;
})
),
// need to specify type, otherwise compile error
handle(actions.reorderParams, (state, { payload }) =>
produce(state, (draft: Draft<Param[]>) => {
draft.splice(payload.fromIndex, 1);
draft.splice(payload.toIndex, 0, state[payload.fromIndex]);
})
), But that is a minor inconvenience, I don't think it matter much. Edit: Looking at another angle, specifying the draft type makes the code alot easier for those who are not familiar with Immer, so I think it is more a plus than a minus here |
This change looks like a breaking change to me! |
I understand the motivation behind |
# [2.0.0](v1.4.1...v2.0.0) (2019-06-15) ### Features * export immutibility type helpers in public API ([b723d35](b723d35)) * make DeepImmutable optional in input/prev state ([0f35d7f](0f35d7f)), closes [#58](#58) [#55](#55) ### BREAKING CHANGES * The input/prev state argument in createHandlerMap (AKA handleAction) and returning reducer of createReducer will not obligated to be Immutable data structure by Deox which in turn can lead to changes in handler's and reducer's return type.
# [2.0.0](v1.4.1...v2.0.0) (2019-06-15) ### Features * export immutibility type helpers in public API ([b723d35](b723d35)) * make DeepImmutable optional in input/prev state ([0f35d7f](0f35d7f)), closes [#58](#58) [#55](#55) ### BREAKING CHANGES * The input/prev state argument in createHandlerMap (AKA handleAction) and returning reducer of createReducer will not obligated to be Immutable data structure by Deox which in turn can lead to changes in handler's and reducer's return type.
Greetings.
I am having some trouble passing the state to other functions:
Is there a way to "disable" The DeepImmutable type wrapper? I understand that it can prevent acidental mutations, but I think it should be optional
I tried the following:
The import gives the following warn:
unable to resolve path to module
, but that is a @typescript-eslint bug I think, because it compiles.Also as a minor incovenience: I am using immer, and because of the immutable wrapper I need to specify the draft type(
(draft: Draft<State>)=>
) when I usingsplice
or other commands inside the draft function.The text was updated successfully, but these errors were encountered: