elgerlambert / redux-localstorage

Store enhancer that syncs (a subset) of your Redux store state to localstorage.
MIT License
1.32k stars 107 forks source link

Fixed incorrect slicing when slice is 0 or null #63

Open electerious opened 7 years ago

electerious commented 7 years ago

It's currently not possibly to save a path with the value 0 or null because the if returns false when obj[key] is 0 or null. Caused me a lot of headache.

I saw you're already working on v1.0, but I hope you're releasing this a bugfix for the current version. It's causing a lot of trouble in my application.

Thanks!

johndturn commented 7 years ago

@elgerlambert Any idea on when this should be fixed and pushed out? Until that point, this is a blocker for me to use this in my application. Otherwise, it works really well!

giannif commented 7 years ago

@jdt1204 you can use a custom slicer passed to persistState in the meantime

const slicer = paths => state => {
    const subset = {}
    paths.forEach(path => {
        // default implementation does a falsy check on state[path],
        // which means false doesn't save hrmph
        subset[path] = state[path]
    })
    return subset
}

compose(applyMiddleware(...middleware), persistState(localStorageProps, { slicer }), devTools)