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.

Usage with seamless-immutable

See original GitHub issue

Hey, I’m trying to use this library with seamless-immutable. I created a transform like this:

let immutableTransform = createTransform(
        (inboundState) => inboundState.asMutable? inboundState.asMutable({deep: true}) : inboundState,
        (outboundState) => immutable(outboundState)
    )

But the immutable wrapper around the data seems to get discarded at some point, meaning that my reducers break as they rely on the wrapper methods. Is there anything else I need to add?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
josev55commented, May 4, 2017

I know this is closed but if you implement a transformer like this (view the attached code) it works really well.

import R from 'ramda'
import Immutable from 'seamless-immutable'

const isImmutable = R.has('asMutable')

const convertToJs = (state) => state.asMutable({deep: true})

const fromImmutable = R.when(isImmutable, convertToJs)

const toImmutable = (raw) => Immutable(raw)

export default {
  out: (state) => {
    state.mergeDeep = R.identity
    return toImmutable(state)
  },
  in: (raw) => {
    return fromImmutable(raw)
  }
}
4reactions
hilkeheremanscommented, Jan 1, 2018

For those of you using v5 and having trouble, I grabbed these transformers + whipped up a custom stateReconciler that helps you use seamless-immutable and avoid the dreaded state.merge is not a function error you get when processing actions after rehydration.

Thanks to @josev55 and @robclouth for the original transforms, a variant of which is also included in this lib!

https://github.com/hilkeheremans/redux-persist-seamless-immutable

Read more comments on GitHub >

github_iconTop Results From Across the Web

rtfeldman/seamless-immutable - GitHub
Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects. - GitHub - rtfeldman/seamless-immutable: ...
Read more >
seamless-immutable - npm
Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.. Latest version: 7.1.4, ...
Read more >
Why I like seamless-immutable with React and Redux - Medium
The case for seamless-immutable​​ This simplifies React component development. Reading the properties of immutable state is no different than ...
Read more >
seamless-immutable examples - CodeSandbox
Learn how to use seamless-immutable by viewing and forking example apps that make use of seamless-immutable on CodeSandbox. ; reactypePrototyping tool for React/ ......
Read more >
React reducers & seamless-immutable - redux - Stack Overflow
{ ...state, loading: action.payload } and state.merge({ loading: action.payload }) is the same, but Immutable.merge ...
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