question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement direct mutation support?

See original GitHub issue

Posted this initially to #10 but it’s offtopic over the so I’m pulling it here.

Have you considered supporting mutating the state too? I think this method could be used to implement very mobx like api for Redux.

Eg. add support for this:


function Counter() {
	const state = useReduxState();
	return <button onClick={() => state.count++}>{count}</button>;
}

The implementation could go like this:

  1. User does state.foo.bar = 1 in a event handler
    • it should be banned during the render tick
  2. Record that change as a immer patch {"op": "replace", "path": ["foo", "bar"], "value": 1}
  3. Create redux action from like
{
  type: "IMMER_PATCH",
  patch:  {"op": "replace", "path": ["foo", "bar"], "value": 1},
}
  1. And apply it using applyPatches from immer in a reducer. It would support all the redux goodies: Devtools, Time-travel, action serialization etc.

Kinda getting excited about this 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
theKasheycommented, Mar 29, 2019

Do you know the limitations of this? I’ve read about the limitations of the spread operator in the tracking part but I can’t think of any problem in the mutation part.

https://github.com/theKashey/memoize-state/issues/26 - the only limitation so far. We likely have a solution for spreads.

1reaction
theKasheycommented, Mar 26, 2019

immer is working like a magic. But

Have you considered supporting mutating the state too?

This is something every new comer want, this is something every author of a brand new state management library want to introduce.

This is something I dont like to have. Idea is to separate actions and changes. To move side effects to sagas, to respond to one action from multiple reducers, to have easy way to debug and easy way to reason about.

Something like teaming Redux and useReducer - might be cool, but also catastrophic.


From another point of view - yes, this could be done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Direct mutation analysis by high-throughput sequencing - NCBI
Although the PacBio RS instrument could help identify germline structural variants as a supplement to a whole genome run with the Illumina or ......
Read more >
Practical use cases for AWS AppSync Pipeline Resolvers
We demonstrate how a direct Lambda resolver can be bound to both Mutation and Query fields, and how we can still use a...
Read more >
Mutate Resources | Kyverno
A JSON Patch, implemented as a mutation method called patchesJson6902 , provides a precise way to mutate resources and supports the following ...
Read more >
Circulating tumour DNA analysis to direct therapy in advanced ...
Interpretation ctDNA testing offers accurate, rapid genotyping that enables the selection of mutation-directed therapies for patients with ...
Read more >
Mutations | Vuex
You cannot directly call a mutation handler. ... It is a commonly seen pattern to use constants for mutation types in various Flux ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found