omi/README.md

156 lines
4.5 KiB
Markdown
Raw Normal View History

2017-12-30 17:55:11 +08:00
<p align="center">
2018-04-26 09:19:34 +08:00
<a href="##Omi"><img src="http://images2015.cnblogs.com/blog/105416/201701/105416-20170120114244046-622856943.png" alt="Omi"></a>
2017-12-30 17:55:11 +08:00
</p>
<p align="center">
2018-04-26 09:19:34 +08:00
Open and modern framework for building user interfaces.
2017-12-30 17:55:11 +08:00
</p>
<p align="center">
2018-04-26 09:19:34 +08:00
<a href="https://circleci.com/gh/AlloyTeam/omi/tree/master"><img src="https://img.shields.io/circleci/project/AlloyTeam/omi/master.svg" alt="Build Status"></a>
<a href="https://www.npmjs.com/package/omi"><img src="https://img.shields.io/npm/v/omi.svg" alt="Version"></a>
<a href="https://www.npmjs.com/package/omi"><img src="https://img.shields.io/npm/dm/omi.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-04-26 09:19:34 +08:00
## Hello Omi
2018-02-25 16:06:09 +08:00
``` 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) {
2018-04-26 09:19:34 +08:00
this.name = 'Hello Omi'
2018-02-25 16:06:09 +08:00
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>
}
}
2018-04-26 11:41:27 +08:00
Omi.render(<App />, '#container')
2018-02-25 16:06:09 +08:00
```
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(){
2018-04-26 09:19:34 +08:00
this.$store.rename('Hello Omi')
2018-02-25 16:06:09 +08:00
}
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
## Install
2017-03-23 07:53:17 +08:00
2018-02-25 16:06:09 +08:00
``` bash
2018-04-26 09:19:34 +08:00
npm install omi
2018-02-25 16:06:09 +08:00
```
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-04-26 17:02:39 +08:00
* [https://unpkg.com/omi@1.8.1/dist/omi.min.js](https://unpkg.com/omi@1.8.1/dist/omi.min.js)
* [https://unpkg.com/omi@1.8.1/dist/omi.js](https://unpkg.com/omi@1.8.1/dist/omi.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.