QRedux bundle qmlified Redux and Immutability-Helper plus few utilities into a single package for using Redux in QML.
qpm install com.github.benlau.qredux
import QRedux 1.0
QRedux.createStore(reducer, [preloadedState], [enhancer])
It is equivalent to Redux.createStore()
QRedux.combineReducers(reducers)
It is equivalent to Redux.combineReducers()
QRedux.applyMiddleware(...middlewares)
It is equivalent to Redux.applyMiddleware()
QRedux.bindActionCreators(actionCreators, dispatch)
It is equivalent to Redux.bindActionCreators()
QRedux.compose(...functions)
It is equivalent to Redux.compose()
QRedux.update()
Mutate a copy of data without changing the original source. It is equivalent to ImmutabilityHelper.update().
QRedux.diff(prevState, currentState)
Compare the different between prevState and currentState. Return undefined if they are the same.
QRedux.patch(dest, changes)
Apply the changes to dest object. It will copy attributes from changes to dest only if such attribute is also existed on dest object.
QRedux.mapReducers(mappingTable)
The mapReducers helper function turns multiple reducers into a single reducing function according to the mapping table.
function addTask(state, action) {
...
}
function removeTask(state, aciton) {
...
}
var table = {
"addTask" : addTask,
"removeTask": removeTask
}
var reducer = QRedux.mapReducers(table);
The resulting reducer read from the input action type, and find a corresponding reducer according to the mapping table. Only one of the reducer will be invoked.
QRedux.chainReducers(reducers)
The chainReducers helper funciton turns multiple reduces into a single reducing function that will be processed sequentially.
function reducer1(state, action) {
switch (action.type) {
/* ... */
}
}
function reducer2(state, action) {
switch (action.type) {
/* ... */
}
}
var reducer = QRedux.chainReducers([reducer1, reducer2]);
QRedux.signalProxyMiddleware(proxy)
QRedux.syncMiddleware(provider)