Giter Site home page Giter Site logo

Comments (5)

mschipperheyn avatar mschipperheyn commented on May 19, 2024

Thanks. I'll take your remarks and add them to the test (feel free to do that, if you like).

from normalizr-immutable.

mschipperheyn avatar mschipperheyn commented on May 19, 2024

Thinking about this a bit more, this is likely caused by the fact that the entities structure is a record and I basically abuse the Record api by creating the Record definition with the entities result. This seemed like a good idea at the time to be able to keep the ability for dot-property access in place.

This is an unwanted side effect. The most obvious workaround instead of merging is to create a new Record with the content of the original record and the new result. I suppose I could create a helper for that.

Another option would be to drop this Record approach entirely and use a map, which is the proper way of doing this, but at the expense of dot-property access.

from normalizr-immutable.

mschipperheyn avatar mschipperheyn commented on May 19, 2024

I just had an idea. What if the result key would contain proxies instead of ids? In that case, you would never have to access entities directly and the entities structure could be just be based on a regular map.

Alternatively, even if we don't do that, the relation could be like so, and you could merge on the Record schema keys.

entities:{//Record with articles as a schema key
  article:{//Map with id-object relations
      3:{},
      5:{}
  }
}

If you use the proxy, this would be minimally impactful on your code. The proxy would abstract the map access away mostly. I imagine it might also be more performant.

 renderRow (rowData) {

    const { articleReducer, actions } = this.props;
    const articleObject = articleReducer.entities.articles[rowData];

    return (
        <Article
            post = {articleObject}
            {...actions} />
    );
}

render () {

    return (
        <ListView
            dataSource={ this.state.dataSource.cloneWithRows(this.props.articleReducer.result.toArray())}
            renderRow={ this.renderRow.bind(this) }
        />
    );
}

//would become

renderRow (rowData) {

    const { articleReducer, actions } = this.props;
    const articleObject = articleReducer.entities.articles.get(rowData);

    return (
        <Article
            post = {articleObject}
            {...actions} />
    );
}

render () {

    return (
        <ListView
            dataSource={ this.state.dataSource.cloneWithRows(this.props.articleReducer.result.toArray())}
            renderRow={ this.renderRow.bind(this) }
        />
    );
}

I think I will make this an option, so people can choose between the approaches. WDYT?

from normalizr-immutable.

mschipperheyn avatar mschipperheyn commented on May 19, 2024

Ok, added to 0.0.3-rc branch

from normalizr-immutable.

rewmike avatar rewmike commented on May 19, 2024

Though I am not currently using getState/reducerKey, that seems like a viable solution.

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.