1.2.1 • Published 4 months ago

reaxes v1.2.1

Weekly downloads
-
License
WTFPL
Repository
-
Last release
4 months ago

What's This

reaxes的设计哲学是:应用的逻辑应该与其他模块解耦,特别是视图用户输入

  • 此库可以让你以响应式编程思维来构建你的应用的核心逻辑,无论是web前端还是nodejs,只要宿主环境支持Proxy即可以运行.
  • 将复杂的业务逻辑从视图组件中抽离, 数据和逻辑将在应用的任何地方可用,而不再是组件和hooks中了.
  • 跨视图同构你的应用,一套逻辑,可以在react,vue中轻易通用而不用修改任何组件代码.甚至native app , web , 小程序中都可以通用,只需要根据宿主环境做些判断.

Installation

$ npm i -S reaxes

Documents

https://kane-7.gitbook.io/reaxes-document

Playground

Using reaxes to build core logic of your app

// reaxels/counter.ts
import { createReaxable , obsReaction } from 'reaxes';

export const reaxel_Counter = reaxel(() => {
   //create a reactive store , so you can subscribe changes when you need.
   const { store , setState } = createReaxable({
      count : 0
   });
   
   return {
      get count(){
         return store.count;
      } ,
      setCount( count: number ){
         setState({ count });
      }
   }
})

Using with vallina JS

// when count changed, refresh DOM
import { reaxel_Counter } from './reaxels/counter';
import { obsReaction } from 'reaxes';

function render(){
   const { count , setCount } = reaxel_Counter();
   
   const div = document.createElement('div');
   div.onclick = () => setCount(count + 1);
   div.innerText = count;
   return div;
}

//listen store.count , once it changes,render() will be re-runed automatically
obsReaction(
   ( first , dispose ) => {
      document.write(render());
      if(first){
         console.log('div element mounted');
      }
   } ,
   //place all observable props here
   () => [ reaxel_Counter().count ]
);

using with React

// there is no need to use obsReaction for every component
// because reaxper will do this automaticlly
// all you need is just to wrap you components with reaxper();
import { reaxper } from 'reaxes-react';
import { reaxel_Counter } from './reaxels/counter';

// functional component
export const Count = reaxper(() => {
   const {count,setCount} = reaxel_Counter();
   
   return <div onClick = { () => setCount(count+1) }>
      count:{ count }
   </div>;
});

// or use class component
import { Component } from 'react';

@reaxper
class CountComponent extends Component {
   
   render(){
      const {count,setCount} = reaxel_Counter();
      
      return <div onClick = { () => setCount(count+1) }>
         count:{ count }
      </div>;
   }
}

using with Vue2

<template>
   <div @click="setCount()">
      {{ count }}
   </div>
</template>
<script>
   import { reaxel_Counter } from './reaxels/counter';
   
   export default {
      status(){
         const {count} = reaxel_Counter();
         return { count };
      },
      methods:{
         setCount(){
            const {count,setCount} = reaxel_Counter();
            setCount(count+1);
         }
      }
   }
</script>
1.2.0

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago

1.2.1

4 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.1.4

4 months ago

1.1.3

4 months ago

1.1.2

4 months ago

1.0.6-beta.8

4 months ago

1.0.6-beta.7

4 months ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.6

2 years ago

0.10.9

3 years ago

0.10.10

3 years ago

0.10.11

3 years ago

0.10.12

3 years ago

0.10.7

3 years ago

0.10.13

3 years ago

0.10.8

3 years ago

0.10.3

3 years ago

0.10.4

3 years ago

0.10.5

3 years ago

0.10.6

3 years ago

0.10.2

3 years ago

0.10.1

3 years ago

0.9.30

3 years ago

0.9.29

3 years ago

0.9.28

3 years ago

0.9.27

3 years ago

0.9.26

3 years ago

0.9.25

3 years ago

0.9.24

3 years ago

0.9.23

3 years ago

0.9.22

3 years ago

0.9.21

3 years ago

0.9.20

3 years ago

0.9.19

3 years ago

0.9.18

3 years ago

0.9.17

3 years ago

0.9.16

3 years ago

0.9.15

3 years ago

0.9.14

3 years ago

0.9.13

3 years ago

0.9.12

3 years ago

0.9.11

3 years ago

0.9.10

3 years ago

0.9.9

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago