/qredux

Redux for QML

Primary LanguageJavaScriptApache License 2.0Apache-2.0

Redux for QML

QRedux bundle qmlified Redux and Immutability-Helper plus few utilities into a single package for using Redux in QML.

Installation

qpm install com.github.benlau.qredux

Reference

  1. My first attempt to use Redux in a QML application – Medium

API

import QRedux 1.0

QRedux.createStore(reducer, [preloadedState], [enhancer])

It is equivalent to Redux.createStore()

API Reference ‧ Redux

QRedux.combineReducers(reducers)

It is equivalent to Redux.combineReducers()

API Reference ‧ Redux

QRedux.applyMiddleware(...middlewares)

It is equivalent to Redux.applyMiddleware()

API Reference ‧ Redux

QRedux.bindActionCreators(actionCreators, dispatch)

It is equivalent to Redux.bindActionCreators()

API Reference ‧ Redux

QRedux.compose(...functions)

It is equivalent to Redux.compose()

API Reference ‧ Redux

QRedux.update()

Mutate a copy of data without changing the original source. It is equivalent to ImmutabilityHelper.update().

Immutability Helpers - React

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)