andyyxw / cans

🍻 A framework for building React MobX application

Home Page:http://cans.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logo

npm npm circle David

A framework for building React MobX application.

quick start

import cans, { inject } from 'cans'
import { BrowserRouter, Route } from 'cans/router'

const app = cans()

// model
app.model({
  namespace: 'counter',
  state: {
    count: 0
  },
  actions: {
    incr() {
      this.count += 1
    },
    decr() {
      this.count -= 1
    }
  },
  computed: {
    content() {
      return `Count: ${this.count}`
    }
  }
})

// view
const Counter = inject(({ models })) => {
  return (
    <div>
      <span>{models.counter.content}</span>
      <button onClick={models.counter.incr}>+</button>
      <button onClick={models.counter.decr}>-</button>
    </div>
  )
}

// router
const route = () => (
  <BrowserRouter>
    <Route path='/' component={Counter} />
  </BrowserRouter>
)
app.route(route)

// mount the app
app.start(document.querySelector('#root'))

Documents

Posts

Plugins

Examples

πŸ‘€ See more examples in cans-example

Build

$ yarn

$ yarn test # unit-test

$ yarn run example # run example

See Also

License

MIT License

About

🍻 A framework for building React MobX application

http://cans.js.org


Languages

Language:JavaScript 70.0%Language:TypeScript 30.0%