-
-
Notifications
You must be signed in to change notification settings - Fork 859
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
Api name #24
Comments
Produce? Next? Mutate? Modify? |
I was thinking about it too. Since it was designed primarily with redux in mind. i think the idiomatic name should contain redux- |
@Gregjarvez this isn't coupled to redux though. It's for anything that you need to update immutably. For example, I've used it in just plain Regarding the actual name, I think "Create the next immutable state" from the README really captures the essence of what @mweststrate Of your suggestions, I like |
I like |
I named similar function On the other side
I think update, mutate, or modify are also good. I came up also with Or two or more words would be probably too verbose for helper library. |
Some ideas:
I like having |
Or just
function insertItem(array, action) {
return ✏(array, draft => {
draft.splice(action.index, 0, action.item)
})
} :) edit: that doesn't compile. Too bad, would be sooo cool. |
I'm thinking about "transform the current state to produce the next state according to this recipe that expresses how a draft state should be changed" |
"Transform" implies mutations, to me.
🤔 |
if the draft eventually becomes the next state
:) |
I think @alexkrolick brings up a good point, transform might imply modification existing data for many. produce probably makes it clearer something new is created function insertItem(array, action) {
return produce(array, draft => {
draft.splice(action.index, 0, action.item)
})
} |
Definitely not immer. The Urban Dictionary defines immer as someone who IMs a lot. |
two ideas:
const immer = require('immer').default;
const {createStore} = require('redux');
// proposal: if immer api look this way (fn, state, ...args):
const transform = (fn, state, ...args) => immer(state, draft => fn(draft, ...args));
//-----------------------------------------------
const initialState = {
animals: ['cat', 'dog']
};
const addAnimal = (state, action) => {
state.animals.push(action.animal);
};
const reducer = transform.bind(null, (state, action) => {
switch (action.type) {
case 'add':
addAnimal(state, action);
break;
}
});
const store = createStore(reducer, initialState);
store.subscribe(() => {
console.log("STATE", store.getState())
});
store.dispatch({type: 'add', animal: 'monkey'});
store.dispatch({type: 'add', animal: 'chicken'}); though this is one liner but having such things in library out-of-the-box could be nice. Or it could use curry instead of partial application (related: integration with Redux #31 (but this is not only Redux related. This pattern could be helpful in many things, where we would like to store some recipe for transform for later use). |
@hex13 file a new issue for that? A separate thread would be nice. |
|
Done |
I am not too excited about
immer
as function name as it is undescriptive. What should the idiomatic name be?Transform? Update? withMutations? Make?
The text was updated successfully, but these errors were encountered: