All Projects → QianmiOpen → iflux2

QianmiOpen / iflux2

Licence: BSD-3-Clause License
Reactive state container (based on immutable) for React or ReactNative, inspired by mapreduce.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to iflux2

Reactjs101
從零開始學 ReactJS(ReactJS 101)是一本希望讓初學者一看就懂的 React 中文入門教學書,由淺入深學習 ReactJS 生態系 (Flux, Redux, React Router, ImmutableJS, React Native, Relay/GraphQL etc.)。
Stars: ✭ 4,004 (+7908%)
Mutual labels:  flux, immutablejs
universal-routed-flux-demo
The code in this repo is intended for people who want to get started building universal flux applications, with modern and exciting technologies such as Reactjs, React Router and es6.
Stars: ✭ 31 (-38%)
Mutual labels:  flux, immutablejs
ballade
For unidirectional data flow.
Stars: ✭ 44 (-12%)
Mutual labels:  flux, immutablejs
React Quick Tutorial
🚀 讓你用最短時間,充分體會 React 的脈絡思維
Stars: ✭ 633 (+1166%)
Mutual labels:  flux, immutablejs
showcase-app-react-native
Aplicativos nacionais feitos com React Native
Stars: ✭ 114 (+128%)
Mutual labels:  reactnative
SwiftUI-Flux
🚀 This is a tiny experimental application using SwiftUI with Flux architecture.
Stars: ✭ 52 (+4%)
Mutual labels:  flux
gitops-playground
Reproducible infrastructure to showcase GitOps workflows and evaluate different GitOps Operators on Kubernetes
Stars: ✭ 77 (+54%)
Mutual labels:  flux
react-native-web-view
An implementation of React Native's WebView that allows for postMessage on iOS devices.
Stars: ✭ 13 (-74%)
Mutual labels:  reactnative
react-native-jsi-template
Template library and blog that explain how JSI modules are built from scratch in React Native
Stars: ✭ 84 (+68%)
Mutual labels:  reactnative
k3s-gitops
My home Kubernetes (k3s) cluster managed by GitOps (Flux)
Stars: ✭ 26 (-48%)
Mutual labels:  flux
RxReduxK
Micro-framework for Redux implemented in Kotlin
Stars: ✭ 65 (+30%)
Mutual labels:  flux
sketch-style-to-react-native
Sketch plugin that copies an element's styles in React Native way directly to your Mac clipboard.
Stars: ✭ 37 (-26%)
Mutual labels:  reactnative
react-native-viewpager-indicator
修改自react-native-scrollable-tab-view,增加了根据文字内容适配下划线长度的功能。
Stars: ✭ 52 (+4%)
Mutual labels:  reactnative
useReduction
useReducer without boilerplate
Stars: ✭ 36 (-28%)
Mutual labels:  flux
Vuex-Alt
An alternative approach to Vuex helpers for accessing state, getters and actions that doesn't rely on string constants.
Stars: ✭ 15 (-70%)
Mutual labels:  flux
Minimal-React
Minimal React + Redux starter kit for experiments.
Stars: ✭ 43 (-14%)
Mutual labels:  flux
FlashCards
Learning Blazor By Creating A Flash Cards Application
Stars: ✭ 17 (-66%)
Mutual labels:  flux
k3s-gitops
GitOps principles to define kubernetes cluster state via code
Stars: ✭ 103 (+106%)
Mutual labels:  flux
ArtShredder
📱Banksy Shredder for iOS
Stars: ✭ 41 (-18%)
Mutual labels:  flux
gitops-build-lib
Jenkins pipeline shared library for automating deployments via GitOps
Stars: ✭ 23 (-54%)
Mutual labels:  flux

New Idea, New the World. 🔥🔥🔥

技术也是时尚驱动的,我们常常臣服于时尚,面对快速的变化常常让我们局促不安, 开始焦虑,唯恐错过了些什么。怎么打破这种焦虑?需要在快速变化得世界里保持清醒, 保持独立的思考和认知。 让我们回归到技术的本质, 因为解决了真实的问题,技术才变得有价值。 真正牛*的技术,都是静悄悄的跑在线上...

iflux2 🚀🚀🚀

NPM

Reactive and Predictable state container for React or ReactNative.

  • Thanks Immutable.js
  • Thanks MapReduce
  • Thanks Functional Reactive Programming.

iflux

很早很早之前,我们爱上了React and immutable,所以就有了很简单的iflux。

iflux = immutable.js + react.js

NPM

保持简单

+-----------------------+
|       WebApi          |
+-----------------------+
          |  
         \|/
+-----------------------+
|   Store(immutable)   |<-----+
+-----------------------+      |
           | //es5 style       |
           | StoreMixin        | msg(EventEmitter)
          \|/                  |
+------------------------+     |
|     React App          |-----|
+------------------------+
|      <Layout>          |
|        <SearchForm/>   |
|        <Toolbar/>      |
|        <DataGrid/>     |
|       </Layout>        |
+------------------------+

优点:

  • 简单直接,几乎没有什么规则
  • 单根数据源(single data source)
  • Immutable fronted UI
  • High Performance

但是随着业务的不断的发展,数据层的复杂度也在上升。这时候iflux就会暴露出很多的缺点

  • Big Store, Store中大量的数据和业务的处理,代码膨胀的厉害
  • Store是单例,不销毁,有共享的问题
  • store的数据通过props不断的透传,代码写的很费劲
  • 大量的数据之间的依赖关系,需要手动的保证和处理

怎么解决?

  • 使用MapReduce的理念解决big Store
  • 使用@Relax自动注入store中的数据和事件
  • Store不再是单例
  • 使用FRP的理念, 简单的实现反应式数据,抽象源数据和派生数据

这就是我们的iflux2

+------------------+
|     BFF-API      |
+------------------+
        ||
        \/
+------------------+
|     WebApi       |
+------------------+
        ||
        \/
+------------------+
|     Store        | ====> [Actor1, Actor2, Actor3]
+------------------+
        ||
        \/
+------------------+
|  @StoreProvider  |
+------------------+
        ||
        \/
+------------------+
|     @Relax       |
+------------------+
        ||
        \/
+------------------+
|     QL/DQL       |
+------------------+

例子

→ tree -L 2                                                                                              [c6c2861]
.
├── actor
│   └── counter-actor.js
├── component
│   └── counter.js
├── index.html
├── index.js
├── package.json
├── ql.js
├── store.js
├── webapi.js
└── webpack.config.js

2 directories, 9 files
//counter-actor.js
import { Actor, Action } from 'iflux2'


export default class CounterActor extends Actor {
  defaultState() {
    return {
      count: 0
    }
  }

  @Action('increment')
  increment(state) {
    return state.update('count', count => count + 1)
  }

  @Action('decrement')
  decrement(state) {
    return state.update('count', count => count - 1)
  }
}
//store.js
import { Store } from 'iflux2'
import CounterActor from './actor/counter-actor'


export default class AppStore extends Store {
  bindActor() {
    return [
      new CounterActor
    ]
  }

  constructor(props) {
    super(props)
    if (__DEV__) {
      //you can use _store directly in browser's console
      window._store = this
    }
  }

  //;;;;;;;;;;;;;;;;;Action;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  increment = () => {
    this.dispatch('increment')
  };

  decrement = () => {
    this.dispatch('decrement')
  };
}
//index.js
import React, { Component } from 'react'
import { render } from 'react-dom'
import { StoreProvider } from 'iflux2'
import AppStore from './store'
import Counter from './component/counter'

// debug: true 更多的console信息
@StoreProvider(AppStore, {debug: true})
export default class CounterApp extends Component {
  render() {
    return (
      <Counter/>
    )
  }
}

render(<CounterApp/>, document.getElementById('app'))
//counter.js
import React, { Component } from 'react'
import { Relax } from 'iflux2'
import { countQL } from '../ql'
const noop = () => {}


@Relax
export default class Counter extends Component {
  static defaultProps = {
    count: 0, //Inject by store's count
    countQL,  //calculate by store's bigQuery
    increment: noop, //Inject by store's increment
    decrement: noop //Inject by store's decrement
  };


  render() {
    const { count, countQL, increment, decrement } = this.props

    return (
      <div>
        <a href='javascript:void(0);' onClick={increment}>increment</a>
        <br/>
        <span>{ count }</span>
        <br/>
        <span>{ countQL }</span>
        <br/>
        <a href='javascript:void(0);' onClick={decrement}>decrement</a>
      </div>
    )
  }
}
//ql.js
import { QL } from 'iflux2'

export const countQL = QL('countQL', [
  'count',
  (count) => `QL:${count}`
]);

how to use?

npm install iflux2 --save

web

//web .babelrc
{
  "presets": ["es2015", "react", "stage-3"],
  "plugins": [
    "transform-decorators-legacy", //required, 必须在class-properties之前!
    "transform-class-properties",
    "transform-es2015-modules-commonjs",
    "transform-flow-strip-types",
    "transform-runtime"
  ],
  "env": {
    "production": {
      "plugins": [
        "transform-react-constant-elements",
        "transform-react-inline-elements"
      ]
    }
  }
}

react-native

//react-native .babelrc
{
  "presets": ["react-native"],
  "plugins":[
    "transform-decorators-legacy"
  ]
}
➜  Hello tree -L 1
.
├── __tests__
├── android
├── index.android.js
├── index.ios.js
├── ios
├── node_modules
├── package.json
├── react-dom //拷贝这个react-native mock的react-dom
├── tsconfig.json
├── typings
└── yarn.lock

6 directories, 5 files
//package.json
"scripts": {
  "postinstall": "npm install ./react-dom"
}

react-native demo可以参考 https://github.com/QianmiOpen/iflux2/tree/master/examples/iflux2Native

more examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].