• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    JavaScript
  • Created almost 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Effects+View+Actions(React distributed state management solution with rxjs.)

React EVA

Effects+View+Actions(React distributed state management solution with rxjs.)

Background

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.

Features

  • Learning easier
  • Smaller than redux
  • Faster than one-way data stream, Because when we manage the state distribution, the entire React tree will not be fully redrawn due to a state change.
  • More elegant than react ref
  • Safer than react ref, Because the traditional way to use the React Ref API is to make it easy for users to access private methods, which is not a problem with React EVA.
  • Support React Hooks

Already used products

Install

npm install --save react-eva

Usage

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")
);

API

1. 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()
2. 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)=>{})
3. 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.)

4. 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.)

5. mergeActions(...actions : Object) : Object

It is used for merge multi actions.

6. createEffects(callback : ($ : (type : String, filter : Function)=>Observable)=>{}) : Function

It is used to create a side-effect execution environment.

LICENSE

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.

More Repositories

1

redux-callbag

🕺🕺Redux middleware for action side effects with callbag 👉< 1KB
JavaScript
182
star
2

react-study

React源码分析,需要进一步了解请移步https://github.com/purplebamboo/little-reactjs
JavaScript
173
star
3

doc-scripts

React Document Build Tool Scripts , Like react-scripts of create react app
JavaScript
155
star
4

depath

Path Matcher/Getter/Setter for Object/Array
TypeScript
132
star
5

mfetch

mfetch will provide you with a strong ability to request resource management
JavaScript
93
star
6

awesome-callbags

Callbag Libraries & Learning Material https://github.com/callbag/callbag
86
star
7

callbag-map-promise

Callbag map promise
JavaScript
65
star
8

callbag-delay

callbag delay
JavaScript
60
star
9

immutability-skinable-component

immutability-skinable-component
JavaScript
48
star
10

exp-parser

An expression parser like the angular's parser
JavaScript
41
star
11

kvm

KVM.js 轻量级模块管理器,依赖注入,AMD,Commonjs规范,Promise化
JavaScript
41
star
12

react-propers

Select react doms , and update props.
JavaScript
40
star
13

gub

CLI tool for create an npm package from any repos. 🐳
JavaScript
33
star
14

dot-match

Extremely easy dot path matching tool
JavaScript
29
star
15

qverse

Traverse any data with DPML commands.
JavaScript
25
star
16

immutability

Improve the react components immutability by es6 decorate
JavaScript
14
star
17

react-chrome-boilerplate

Improve your development efficiency to create chrome extension.
JavaScript
9
star
18

github-tag-release

github release by git tags
TypeScript
9
star
19

react-banners

React通用横幅组件
JavaScript
8
star
20

react-snap-svg

react snap.svg
JavaScript
5
star
21

react-stikky

It's very easy to sticky fixed target element.
JavaScript
5
star
22

react-slot-props

slot slot slot , react slot!
JavaScript
5
star
23

react-code-snippet

React Code Snippet
JavaScript
4
star
24

react-site-renderer

JavaScript
3
star
25

awesome-react-suspense

Awesome list of React components with suspense and resources.
3
star
26

react-demo-loader

webpack loader for react demo
JavaScript
2
star
27

dom-imagify

Generates an image from a DOM node using HTML5 canvas
JavaScript
2
star
28

use-element-rect-observer

TypeScript
2
star
29

get-target-cookie

TypeScript
1
star
30

react-doc-renderer

JavaScript
1
star
31

super-plugin

JavaScript
1
star
32

janry.blog.io

1
star
33

clean-ns

Clean Node Modules
JavaScript
1
star
34

janryWang

Config files for my GitHub profile.
1
star
35

deproxy

Downgradable ES Proxy solution
1
star