-
Notifications
You must be signed in to change notification settings - Fork 8
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
@frp-ts/state addition #53
Comments
@PalmZE Looks interesting, I'll try to book some time today to digest this. |
Solid's implementation also looks nice and in fact it's much more composable |
Ok, I played a bit with interface Dog {
name: string;
}
interface House {
dog: Dog;
}
interface AppState {
house: House;
}
const initialState: AppState = { house: { dog: { name: 'Fido' } } };
const storeState = newAtom(initialState)
const storeMethods = produceMany(storeState, {
renameTheDog: (newName: string) => state => {
state.house.dog.name = newName
}
})
const store = { ...storeState, ...storeMethods }
store.renameTheDog('Odif'); |
Btw, any ideas for a better name for |
@raveclassic looks nice 👍 as for a better name, some ideas:
Anyway, I guess jsdoc explaining that the API uses immer internally will do |
I love this concept! I thought immer would fit well here :)
|
@raveclassic Might as well try making a variant with a reducer like approach? const dispatch = newAtomReducer(state, (draft, action: Actions) => {
if (action.type === "toggle") {
const todo = draft.find((todo) => todo.id === action.id)
todo.done = !todo.done
}
})
dispatch({ type: "toggle", id: "1" }) |
@raveclassic, hi!
Would you accept the below feature as a separate frp-ts package\addition to the core package?
Internally it will use immer to support concise mutation syntax.
Motivation
I find it convenient to group store\vm state into a single object and expose a single atom in the API. This leads to some boilerplate when you need to modify parts of the state.
Immer helps a lot, but we still need to use modify calls. This change simplifies this use case.
Besides, some libraries provide this out of the box (SolidJS as example).
The text was updated successfully, but these errors were encountered: