Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
react-eva
Advanced tools
Readme
Effects+View+Actions(React distributed state management solution with rxjs.)
In the long process of practice, we found that the one-way data flow management application state may not be a silver bullet.so we can change the way to make React faster.
npm install --save react-eva
https://codesandbox.io/s/lr68qp453q
import React, { useState } from "react";
import ReactDOM from "react-dom";
import { useEva, createAsyncActions, createEffects } from "react-eva";
const App = ({ actions, effects }) => {
const [state, setState] = useState({ text: "default" });
const { implementActions, dispatch } = useEva({ actions, effects });
implementActions({
getText: () => state.text,
setText: text => setState({ text })
});
return (
<div className="sample">
<div className="text">{state.text}</div>
<button className="inner-btn" onClick={() => dispatch("onClick")}>
button
</button>
</div>
);
};
const actions = createAsyncActions("getText", "setText");
const effects = createEffects(async $ => {
console.log(await actions.getText());
$("onClick").subscribe(() => {
actions.setText("hello world");
});
});
ReactDOM.render(
<App actions={actions} effects={effects} />,
document.getElementById("root")
);
useEva({actions:Object,effects:Function})
It will return the following methods.
property name | description | type | params |
---|---|---|---|
implementActions | it used for batch create state actions method,and it will communicate with externally declared actions. | Function | implementAction(type : String,handler : Function) |
dispatch | It is used to dispatch custom events. | Function | dispatch(type:String,..args : any) |
subscription | It is used to perform side-effect logic.If you set autoRun to false, then you need to call it manually. | Function | subscription() |
connect(options : Object | ReactComponent) : (Target : ReactComponent)=>ReactComponent
The connect's options
property name | description | type |
---|---|---|
autoRun | It is used to auto run the subscription. | Boolean |
The target component will receive the following properties.
property name | description | type | params |
---|---|---|---|
implementActions | it used for batch create state actions method,and it will communicate with externally declared actions. | Function | implementAction(type : String,handler : Function) |
dispatch | It is used to dispatch custom events. | Function | dispatch(type:String,..args : any) |
subscription | It is used to perform side-effect logic.If you set autoRun to false, then you need to call it manually. | Function | subscription() |
subscribes | It is the core object of event communication. | Object |
The output component will receive the following properties.
property name | description | type | params |
---|---|---|---|
actions | This property is designed to internal and external communication of components. | Object | |
effects | This property is designed to handle the side effects of components. | Function | effects(callback : ($ : (type : String, filter : Function)=>Observable)=>{}) |
createActions(...type : String) : Object
It is used for batch declaration of state actions. (Note: The success of calling actions is that the component has been rendered.)
createAsyncActions(...type : String) : Object
It is used for batch declaration of state actions. (Note: All methods will return a Promise object, and we don't have to wait for the component to render completed when we call actions.)
mergeActions(...actions : Object) : Object
It is used for merge multi actions.
createEffects(callback : ($ : (type : String, filter : Function)=>Observable)=>{}) : Function
It is used to create a side-effect execution environment.
The MIT License (MIT)
Copyright (c) 2018 JanryWang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
React distributed state management solution
The npm package react-eva receives a total of 3,714 weekly downloads. As such, react-eva popularity was classified as popular.
We found that react-eva demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.