omi/README.md

161 lines
4.6 KiB
Markdown
Raw Normal View History

2017-12-30 17:55:11 +08:00
<p align="center">
2018-02-25 16:06:09 +08:00
<a href="##Omix"><img src="http://images2017.cnblogs.com/blog/105416/201708/105416-20170807145434955-1872305404.png" alt="Omi"></a>
2017-12-30 17:55:11 +08:00
</p>
<p align="center">
2018-02-25 16:06:09 +08:00
Build UI with JSX - 使用 JSX 创建用户界面
2017-12-30 17:55:11 +08:00
</p>
<p align="center">
2018-02-25 16:06:09 +08:00
<a href="https://circleci.com/gh/AlloyTeam/omix/tree/master"><img src="https://img.shields.io/circleci/project/AlloyTeam/omix/master.svg" alt="Build Status"></a>
<a href="https://www.npmjs.com/package/omix"><img src="https://img.shields.io/npm/v/omix.svg" alt="Version"></a>
<a href="https://www.npmjs.com/package/omix"><img src="https://img.shields.io/npm/dm/omix.svg" alt="Download"></a>
2017-08-02 10:38:21 +08:00
<a href="CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs"></a>
2017-03-09 16:26:06 +08:00
</p>
2017-06-10 13:31:09 +08:00
2018-02-25 16:06:09 +08:00
* [中文文档](./docs/README.md)
2018-02-25 16:24:34 +08:00
* [Omi REPL](https://alloyteam.github.io/omi/repl/)
* [Change Log](https://github.com/AlloyTeam/omi/blob/master/change-log.md)
2017-06-10 13:31:09 +08:00
2017-03-23 07:53:17 +08:00
## Features
2018-02-25 16:24:34 +08:00
* Super fast, [click here!!!!](https://alloyteam.github.io/omi/example/perfs)
2017-03-23 07:53:17 +08:00
* Super tiny size, 7 KB (gzip)
2018-02-25 16:06:09 +08:00
* Good compatibility, support IE8
2017-08-02 11:02:59 +08:00
* Support Scoped CSS, reusable components are composed of HTML, Scoped CSS and JS
2017-03-23 07:53:17 +08:00
* More free updates, each component has a update method, free to choose the right time to update
2018-02-25 16:06:09 +08:00
## Hello Omix
``` js
class Hello extends Omi.Component {
render() {
return <div> Hello {this.data.name}!</div>
}
}
class App extends Omi.Component {
install() {
this.name = 'Omi'
this.handleClick = this.handleClick.bind(this)
}
handleClick(e) {
this.name = 'Omix'
this.update()
}
style() {
return `h3{
color:red;
cursor: pointer;
}`
}
render() {
return <div>
<Hello name={this.name}></Hello>
<h3 onclick={this.handleClick}>Scoped css and event test! click me!</h3>
</div>
}
}
Omi.render(new App(), '#container')
```
2017-03-23 07:53:17 +08:00
2018-02-25 16:06:09 +08:00
## Using Store System
```js
class Store {
constructor(data, callbacks) {
this.name = data.name || ''
this.onRename = callbacks.onRename || function(){}
}
rename(name){
this.name = name
this.onRename()
}
}
class Hello extends Omi.Component {
render() {
return (
//you can also use this.$store.name here. but using data if this is a pure component.
<div> Hello <span>{this.data.name}</span>!</div>
)
}
}
class App extends Omi.Component {
install(){
this.rename = this.rename.bind(this)
}
rename(){
this.$store.rename('Omix')
}
render() {
return (
<div onclick={this.rename}>
<Hello name={this.$store.name}></Hello>
</div>
)
}
}
let app = new App()
let store = new Store({ name : 'Omi' } ,{
onRename :()=>{
app.update()
}
})
Omi.render(app, 'body',{
store
})
```
2017-03-23 07:53:17 +08:00
2018-02-25 16:24:34 +08:00
[→Try it online←](https://alloyteam.github.io/omi/repl/redirect.html)
2018-02-25 16:06:09 +08:00
## omi-cli
2017-03-23 07:53:17 +08:00
2017-08-02 11:02:59 +08:00
```bash
2018-02-25 16:06:09 +08:00
$ npm install omi-cli -g # install cli
2018-02-25 16:24:34 +08:00
$ omi init your_project_name # init project, you can also exec 'omi init' in an empty folder
2018-02-25 16:06:09 +08:00
$ cd your_project_name # please ignore this command if you executed 'omi init' in an empty folder
$ npm start # develop
$ npm run dist # release
2017-03-23 07:53:17 +08:00
```
2018-02-25 16:06:09 +08:00
the latest cli support blow cmd to init omix project, not omi project:
2017-03-23 07:53:17 +08:00
2018-02-25 16:06:09 +08:00
```
omi init your_project_name
```
2017-03-23 07:53:17 +08:00
2018-02-25 16:06:09 +08:00
## Install
2017-03-23 07:53:17 +08:00
2018-02-25 16:06:09 +08:00
``` bash
npm install omix
```
2017-03-23 07:53:17 +08:00
2018-02-25 16:06:09 +08:00
or get it from CDN:
2017-03-23 07:53:17 +08:00
2018-02-25 16:06:09 +08:00
* [https://unpkg.com/omix@1.2.9/dist/omix.min.js](https://unpkg.com/omix@1.2.9/dist/omix.min.js)
* [https://unpkg.com/omix@1.2.9/dist/omix.js](https://unpkg.com/omix@1.2.9/dist/omix.js)
2017-03-23 07:53:17 +08:00
2018-02-25 16:06:09 +08:00
## Plugins
2017-03-23 07:53:17 +08:00
2018-02-25 16:24:34 +08:00
* [omi-tap](https://github.com/AlloyTeam/omi/tree/master/plugins/omi-tap): Support tap event in your Omi project..
* [omi-router](https://github.com/AlloyTeam/omi/tree/master/plugins/omi-router): Router for Omi.
* [omi-finger](https://github.com/AlloyTeam/omi/tree/master/plugins/omi-finger): Omi /[AlloyFinger](https://github.com/AlloyTeam/AlloyFinger) integration.
* [omi-transform](https://github.com/AlloyTeam/omi/tree/master/plugins/omi-transform): Omi /[transformjs](https://alloyteam.github.io/AlloyTouch/transformjs/) integration.
* [omi-touch](https://github.com/AlloyTeam/omi/tree/master/plugins/omi-touch): Omi /[AlloyTouch](https://github.com/AlloyTeam/AlloyTouch) integration.
2017-03-09 16:26:06 +08:00
# License
This content is released under the [MIT](http://opensource.org/licenses/MIT) License.