https://github.com/benlau/qredux
Redux for QML
https://github.com/benlau/qredux
Last synced: 8 months ago
JSON representation
Redux for QML
- Host: GitHub
- URL: https://github.com/benlau/qredux
- Owner: benlau
- License: apache-2.0
- Created: 2016-12-01T15:56:50.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-10T12:01:31.000Z (almost 7 years ago)
- Last Synced: 2025-04-04T20:41:05.801Z (8 months ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 26
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-qt-qml - qredux - Redux for QML. (JavaScript)
README
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](https://medium.com/@benlaud/my-first-attempt-to-use-redux-in-a-qml-application-dc7a21689fb#.w3i809t7m)
API
===
```
import QRedux 1.0
```
**QRedux.createStore(reducer, [preloadedState], [enhancer])**
It is equivalent to Redux.createStore()
[API Reference ‧ Redux](http://redux.js.org/docs/api/)
**QRedux.combineReducers(reducers)**
It is equivalent to Redux.combineReducers()
[API Reference ‧ Redux](http://redux.js.org/docs/api/)
**QRedux.applyMiddleware(...middlewares)**
It is equivalent to Redux.applyMiddleware()
[API Reference ‧ Redux](http://redux.js.org/docs/api/)
**QRedux.bindActionCreators(actionCreators, dispatch)**
It is equivalent to Redux.bindActionCreators()
[API Reference ‧ Redux](http://redux.js.org/docs/api/)
**QRedux.compose(...functions)**
It is equivalent to Redux.compose()
[API Reference ‧ Redux](http://redux.js.org/docs/api/)
**QRedux.update()**
Mutate a copy of data without changing the original source.
It is equivalent to ImmutabilityHelper.update().
[Immutability Helpers - React](https://facebook.github.io/react/docs/update.html)
**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)**