noflux
  • Noflux
  • Choose a language
  • Noflux
    • migration
      • Migration from noflux to v0.x
      • from-v0-to-v1
      • Migration
    • advanced
      • @connect
      • API
      • state
    • Summary
    • basic
      • React
      • Basic
      • state
    • getting-started
  • Noflux
    • Summary
    • advanced
      • state
      • @connect
      • API
    • basic
      • React
      • 基础
      • state
    • migration
      • from-v0-to-v1
      • Migration
      • 从noflux到v0.x
    • getting-started
  • examples
    • README
    • Noflux TodoMVC Example Using TypeScript
Powered by GitBook
On this page
  • Getting started
  • Installation
  • Example
  • Syntax
  • Interfaces
  • Next steps

Was this helpful?

  1. Noflux

getting-started

PreviousstateNextNoflux

Last updated 4 years ago

Was this helpful?

Getting started

Installation

Install @noflux/react package by using :

npm install --save @noflux/react

Example

Here is an Noflux app example. You can also debug it online: .

import React, { Component } from 'react';
import { connect, state } from '@noflux/react';

state.set({
  name: 'jack',
});

@connect
export default class App extends Component {
  render() {
    return (
      <div>
        <input onChange={e => state.set('name', e.target.value)} />
        <p> Hello, my name is {state.get('name')} </p>
      </div>
    )
  }
}

Syntax

class App extends Component {
  //...
}
export default connect(App);
npm install --save-dev babel-plugin-transform-decorators-legacy

And modify the .babelrc file to enable the plugin:

{
  "plugins": ["transform-decorators-legacy"]
}

Code examples in the rest documents will be written using decorators syntax.

Interfaces

Noflux only exports two interfaces, state and connect。

  • state maintains a global unique state and provides methods such as get and set to read/write state.

  • connect will track changes in state and re-render components intelligently.

Next steps

The connect in Noflux is a "decorator" in ES Next but also can run in the ES5 environment:

If you use a JavaScript compiler like , you can use @connect decorator with a sample configuration. Run this command to install decorators plugin:

Noflux uses single source of truth and provide an immutable state, that is similar to .

A component will be re-rendered via , meaning its render method will be called if the value from state.get was changed.

I believe you have had a preliminary impression of Noflux. Let's enter the next chapter: .

npm
https://codesandbox.io/s/z47wLwP8
proposal
Babel
Redux
forceUpdate
basic