teras
v0.0.32
Published
A light weight redux-saga wrapper
Downloads
5
Readme
Teras
Teras is a wrapper-library based on redux, redux-saga and react-router. (Inspired by dva-js)
Installation
This library is published in the NPM registry and can be installed using any compatible package manager.
npm install teras --save
or
yarn add teras
Usage
Init
import Teras from 'teras';
import terasModel from "./models/terasModel";
ReactDOM.render(
<Teras models={[terasModel]}>
<App />
</Teras>
document.getElementById('root')
);
Models
const INITIAL_STATE = {
initlabel: 'Hello World'
};
export default {
namespace: 'terasModel',
state: INITIAL_STATE,
reducers: {},
effects: {
},
};
App
import {core} from 'teras';
const mapStatesToProps = ({terasModel}) => ({
terasModel,
});
function App({dispatch, terasModel}) {
const {initlabel} = terasModel;
return (
<div>
{initlabel}
</div>
);
}
export default core.connect(mapStateToProps)(App);
Socket Connection
function* onReceived(message, {put, select}) {
if (!message) return;
console.log('onReceived');
}
function* onConnected({socket}, {put, select}) {
console.log('onConnected');
}
function* onDisconnected(query, {put, select}) {
console.log('onDisconnected');
}
function* onError() {
console.log('onEror');
}
export default {
namespace: 'chatSocket',
onReceived,
onConnected,
onDisconnected,
onError,
url: `wss://localhost,
};
License
Copyright (C) 2021 Qumon Intelligence
Released under MIT License.