Skip to content
Branch: master
Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
config
dist publish(omis): v2.2.0, add render and reset method Oct 19, 2019
react publish(omis): v2.2.0, add render and reset method Oct 19, 2019
src publish(omis): v2.2.0, add render and reset method Oct 19, 2019
README.md publish(omis): v2.2.0, add render and reset method Oct 19, 2019
package.json

README.md

Omis

1kb store system for React/Preact apps.

Usage

import { $, render } from 'omis'

const Counter = $({
  render() {
    return <div>{$.store.data.count}</div>
  },
  use: ['count']
  //or
  //useSelf: ['count']
})

const App = $({
  render() {
    return (
      <div>
        <Counter />
      </div>
    )
  }
})

render(
  ReactDOM.render, //use Preact.render here when using preact
  <App />,
  '#root',
  {
    data: {
      count: 1
    }
  })

Multi-store injection

import React from 'react';
import ReactDOM from 'react-dom';

import { $, render } from './omis/omis'

const countStore = new class Store {
  data = {
    count: 1,
    msg: 'omis',
    num: Math.random()
  }
  sub = () => {
    this.data.count--
  }
  add = () => {
    this.data.count++
  }
  random = () => {
    this.data.num = Math.random()
  }
}

const nameStore = new class Store {
  data = {
    name: 'hello'
  }
  rename = () => {
    this.data.name = 'bcd'
  }
}

const Counter = $({
  render() {
    const $s = $.store.countStore
    const $ns = $.store.nameStore
    return <>
      <button onClick={$s.sub}>-</button>
      <span>{$s.data.count}</span>
      <button onClick={$s.add}>+</button>
      <div>{Math.random()}</div>
      <div onClick={$ns.rename}>{$ns.data.name}</div>
    </>
  },
  use: {
    countStore: ['count'],
    nameStore: ['name']
  }
})

const App = $({
  render() {
    const $s = $.store.countStore
    return <div>
      <div>{$s.data.msg}</div>
      <button onClick={$s.random}>Click me to updateSelf-{$s.data.num}</button>
      <div>{$s.data.count}</div>
      <Counter></Counter>
    </div>
  },
  useSelf: { countStore: ['num'] }
})

render(
  ReactDOM.render, //use Preact.render here when using preact
  <App />,
  '#root',
  {
    nameStore,
    countStore
  })
You can’t perform that action at this time.