Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const _ = require('lodash');
- const { ORM, Model, attr } = require('redux-orm');
- // define model
- class Event extends Model {
- }
- Event.modelName = 'Event';
- Event.fields = {
- title: attr(),
- };
- // prepare orm and session
- const orm = new ORM();
- orm.register(Event);
- const session = orm.session(orm.getEmptyState());
- // generate sample data
- _.range(100).forEach(index => {
- session.Event.create({
- title: `Event ${index % 2 === 0 ? '!' : '?'}`
- });
- });
- // filter now accepts function callbacks
- const result = session.Event.query.filter(data => {
- // data is a POJO directly from store
- global.console.warn(data);
- return data.title.includes('!');
- });
- global.console.warn(result.count());
- // filter can also be a POJO with attribute spec
- const count = session.Event.query.filter({ title: 'Event !' }).count();
- global.console.warn(count);
Add Comment
Please, Sign In to add comment