Coder Social home page Coder Social logo

Comments (7)

mschipperheyn avatar mschipperheyn commented on May 4, 2024

Can you provide some more code for me to understand. And which version are you using?

from normalizr-immutable.

srghma avatar srghma commented on May 4, 2024

Sorry, I move from normalizr-immutable to vanilla Immutable.fromJS for better handleability.
But there is commit of this issue

I think origin of this issue is that initialState of project reducer is Map({}) there

import { Map } from "immutable"
import * as types from "../projectConstants"

const initialState = Map({})

export default function projects(state = initialState, action = {}) {
  switch (action.type) {
  case types.LOAD_PROJECTS: {
    return state.merge(action.payload)
  }
  default:
    return state
  }
}

And then I merge it like this dispatch(loadProjects(normalized.entities.projects))

And when I try use it state.projects.toString(), it throw Cannot read property 'entities' of undefined error

from normalizr-immutable.

mschipperheyn avatar mschipperheyn commented on May 4, 2024

Ok, at a glance, it seems to me that you should merge entities and not entities.projects.

Also, "property 'entitities' of undefined" suggests that the projectsReducer is not available when that call is made. This could be related to not supplying the reducer reference correctly in the schema definition.

My personal preference is to make the state a Record instead of a Map. I think it's more elegant since it kind of defines an API.

I would define it for instance as

 const ProjectState = Record({
    entities: Map(),
    result: OrderedSet()
})

const initialState = new ProjectState();

from normalizr-immutable.

srghma avatar srghma commented on May 4, 2024

Yes, or I had to use NormalizedRecord as initialState, I just surprised that entities created by "normalizr-immutable" is not compatible with vanilla immutable entities at first glance, I will close the issue, thanks you for your time

P.S. I thought that Record doesn`t have Iterable methods, I was misguided by official documentation 😄

from normalizr-immutable.

mschipperheyn avatar mschipperheyn commented on May 4, 2024

The entities created by normalizr-immutable are simple immutable Records, fully compatible. If you start using the Proxy facilities, you have to take a little more care in how you use things. But for me, the pains are worth it.

One more thing: I recommed using the latest 0.0.4 beta of normalize-immutable. Depending on configuration the 0.0.3 branch uses a Record for the entities structure which was a misguided choice on my part.

from normalizr-immutable.

srghma avatar srghma commented on May 4, 2024

Ok, currently I just teaching react, it seems I will return to normalizr-immutable once)

from normalizr-immutable.

srghma avatar srghma commented on May 4, 2024

OK, I returned to normalizr-immutable, and find out that Records dont have useful Iterable methods (map/filter, just as I say, actually they have them, but they return undefined and will show warnings in future versions, spent plenty of time on that), so I better use Maps
And because there more cozy way to immutate initial state with vanilla fromJS(is that so?), I move to that

from normalizr-immutable.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.