omi/packages/templates-old/omis
dntzhang b9f0d6ae66 chore: change omijs.org to tencent.github.io/omi/ 2019-10-18 11:17:16 +08:00
..
config chore: change omijs.org to tencent.github.io/omi/ 2019-10-18 11:17:16 +08:00
dist chore: change omijs.org to tencent.github.io/omi/ 2019-10-18 11:17:16 +08:00
examples chore: move omis to template-old 2019-10-01 17:01:28 +08:00
src chore: move omis to template-old 2019-10-01 17:01:28 +08:00
test chore: move omis to template-old 2019-10-01 17:01:28 +08:00
.babelrc chore: move omis to template-old 2019-10-01 17:01:28 +08:00
.editorconfig chore: move omis to template-old 2019-10-01 17:01:28 +08:00
.eslintignore chore: move omis to template-old 2019-10-01 17:01:28 +08:00
.eslintrc chore: move omis to template-old 2019-10-01 17:01:28 +08:00
.flowconfig chore: move omis to template-old 2019-10-01 17:01:28 +08:00
LICENSE chore: move omis to template-old 2019-10-01 17:01:28 +08:00
README.CN.md chore: move omis to template-old 2019-10-01 17:01:28 +08:00
README.md chore: move omis to template-old 2019-10-01 17:01:28 +08:00
package.json chore: move omis to template-old 2019-10-01 17:01:28 +08:00

README.md

English | 简体中文

Omis

Functional Component + Store + Scoped Style + Web Components in tiny size

  • Functional style but non-functional programming
  • Structure-Style-Behavior Separation
  • Scoped style supporting
  • Web Components supporting
  • Hyperscript is visually more friendly
  • Each component can have a store and be de-centralized
  • Support global store to share data and update on demand
  • Each component store has an update method that executes the method to customize local refresh components
  • Mini Program(小程序) supporting

Usage

npm i omis
import { render, h } from 'omis'

const Counter = (props, store) => {
  return (
    <div>
      <button onClick={store.sub}>-</button>
      <span>{store.count}</span>
      <button onClick={store.add}>+</button>
    </div>
  )
}

Counter.store = _ => {
  return {
    count: 1,
    add() {
      this.count++
      _.update()
    },
    sub() {
      this.count--
      _.update()
    }
  }
}

Counter.css = `
span{
  color: red;
}
`

render(<Counter />, 'body')

Description of parameters

const Comp = (props, store, _, $) => {

}

Comp.store = (_, $) => {

}
  • _ represents component
  • $ represents globalStore

Quick Start

$ npm i omi-cli -g     # install cli
$ omi init-s my-app    # init project
$ cd my-app            
$ npm start            # develop
$ npm run build        # release

npx omi-cli init-s my-app (npm v5.2.0+)

Web Components

import { define } from 'omis'

const HelloMessage = (props, store) => {
  return (
    <div onClick={store.clickHandler} >
      <div>Hello {props.msg}</div>
      <div>{props.user.name}</div>
      <div>{props.user.age}</div>
    </div>
  )
}

HelloMessage.css = `div{
	color: red;
}`

HelloMessage.store = _ => {
  return {
    clickHandler() {
      _.props.onMyEvent && _.props.onMyEvent(123)
    }
  }
}

HelloMessage.propTypes = {
  msg: String,
  user: Object
}

define('hello-msg', HelloMessage)

Then you can use <hello-msg></hello-msg> anywhere:

<hello-msg msg="Omis" user="{name:'dntzhang', age: 18}"></hello-msg>

<script>
  var ele = document.querySelector('hello-msg')

  ele.addEventListener('myEvent', function(evt){
    console.log(evt)
  })
</script>

Contribution

Develop

npm start example-name

Publish

npm run build

Testing

npm run test

License

MIT