I am pretty new to javascript and redux. My application's state got quite complex, while Redux by itself helps a lot, it lacks the capabilities for specifying which relationships there are within your data.
I am trying to update nested data with redux reducers/actions in javascript. i've tried using Redux-orm library but i get this error from console.
Uncaught SyntaxError: The requested module './../../../lodash/filter.js' does not provide an export named 'default'
I checked if the imports/exports are the source for this error, but i think its something else. Does someone know how to fix this?
My code:
import { Model, fk, attr, ORM } from 'redux-orm'
export class Cursus extends Model {
static get fields() {
return {
id: attr(),
cursus: attr(),
code: attr(),
naam: attr(),
ec: attr(),
}
}
static reducer(action, Cursus, session) {
switch (action.type) {
case 'CREATE_CURSUS': {
Cursus.create(action.payload)
break
}
}
return undefined;
}
}
Cursus.modelName = 'Cursus';
export class Toets extends Model {
static get fields() {
return {
id: attr(),
toets: attr(),
toetsvorm: attr(),
weging: attr(),
ectoets: attr(),
periode:attr(),
programmaleider:attr(),
// foreign key field
cursusId: fk({
to: 'Cursus',
as: 'cursus',
relatedName: 'toetsen',
}),
}
}
static reducer(action, Toets, session) {
switch (action.type) {
case 'ADD_TOETS': {
Toets.create(action.payload)
break
}
}
return undefined;
}
}
Toets.modelName = 'Toets'
export const orm = new ORM()
orm.register(Cursus, Toets)
import { createStore, combineReducers } from 'redux'
import { createReducer } from 'redux-orm'
import { orm } from '../model/Model.js'
const rootReducer = combineReducers({
// Insert the auto-generated Redux-ORM reducer. This will
// initialize our model "tables", and hook up the reducer
// logic we defined on each Model subclass
entities: createReducer(orm)
})
export const store = createStore(
rootReducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);