Comments (5)
Thanks. I'll take your remarks and add them to the test (feel free to do that, if you like).
from normalizr-immutable.
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.
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.
Ok, added to 0.0.3-rc branch
from normalizr-immutable.
Though I am not currently using getState/reducerKey, that seems like a viable solution.
from normalizr-immutable.
Related Issues (14)
- Support deep merge of different normalizr entities HOT 3
- Late binding: ignoring the proxies in certain cases
- "A record is required" error is thrown
- Proper way to merge entities HOT 1
- Compatibility with transit-immutable-js HOT 1
- Cannot read property 'entities' of undefined HOT 7
- 0.0.4 release wish HOT 3
- [SEO] 'normalizr-immutable' package leads to Googlebot rendering blank page on webmasters page
- Unable to import from 'normalizr-immutable' HOT 3
- Unnecessary overhead from harmony-reflect HOT 1
- reducer key per schema? HOT 8
- Map/Record is preferred when object key is referenced HOT 5
- hydrating client stores from server + proxies HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from normalizr-immutable.