Package Exports
- omi
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (omi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
English | 简体中文

Omi - Front End Cross-Frameworks Framework
Merge Web Components, JSX, Virtual DOM, Functional style, observe or Proxy into one framework with tiny size and high performance. Write components once, using in everywhere, such as Omi, React, Preact, Vue or Angular.
Quick Preview
Pass data through the component tree without having to pass props down manually at every level by store, auto update the view on demand.
import { define, render } from 'omi'
class Store {
data = {
count: 1
}
sub = () => {
this.data.count--
}
add = () => {
this.data.count++
}
}
define('my-counter', _ => (
<div>
<button onClick={_.store.sub}>-</button>
<span>{_.store.data.count}</span>
<button onClick={_.store.add}>+</button>
</div>
), {
use: ['count'],
//or using useSelf, useSelf will update self only, exclude children components
//useSelf: ['count'],
css: `span { color: red; }`,
installed() {
console.log('installed')
}
})
render(<my-counter />, 'body', new Store)<my-counter></my-counter>can be used in any framework or no framework, such asdocument.createElement('my-counter')
You can also use useSelf, useSelf only updates itself. When using useSelf, the corresponding attributes are accessed through usingSelf in JSX.
You can also implement computed props through compute, such as:
define('my-counter', _ => (
<div>
<button onClick={_.store.sub}>-</button>
<span>{_.store.data.count}</span>
<button onClick={_.store.add}>+</button>
<div>Double: {_.computed.doubleCount}</div>
</div>
), {
use: ['count'],
compute: {
doubleCount() {
return this.count * 2
}
}
})Path is also supported:
class Store {
data = {
list: [
{ name: { first: 'dnt', last: 'zhang' } }
]
}
}
...
...
define('my-counter', _ => (
...
...
), {
use: [
'list[0].name', //Direct string path dep, accessible through this.using[0]
],
compute: {
fullName() {
return this.list[0].name.first + this.list[0].name.last
}
}
})
Multi-store injection
import { define, render } from 'omi'
define('my-app', _ => {
const store = _.store.storeA
const { data, add, sub } = store
return (
<p>
Clicked: {data.count} times
<button onClick={add}>+</button>
<button onClick={sub}>-</button>
<div>
{_.store.storeB.data.msg}
<button onClick={_.store.storeB.changeMsg}>
change storeB's msg
</button>
</div>
</p>
)
}, {
useSelf: {
storeA: ['count', 'adding'],
storeB: ['msg']
}
})
const storeA = new class Store {
data = {
count: 0,
adding: false
}
sub = () => {
this.data.count--
}
add = () => {
this.data.count++
}
}
const storeB = new class Store {
data = {
msg: 'abc'
}
changeMsg = () => {
this.data.msg = 'bcd'
}
}
render( <my-app /> , 'body', {
storeA,
storeB
})How to Multi-store injection with compute and computed? Very simple:
define('my-app', _ => {
const store = _.store.storeA
const { data, add, sub } = store
return (
<p>
Clicked: {data.count} times
<button onClick={add}>+</button>
<button onClick={sub}>-</button>
<div>
{_.store.storeB.data.msg}
<button onClick={_.store.storeB.changeMsg}>
change storeB's msg
</button>
</div>
<div>{_.computed.dobuleCount}</div>
<div>{_.computed.reverseMsg}</div>
</p>
)
}, {
useSelf: {
storeA: ['count', 'adding'],
storeB: ['msg']
},
compute: {
dobuleCount() {
return this.storeA.data.count * 2
},
reverseMsg() {
return this.storeB.data.msg.split('').reverse().join('')
}
}
})API and Hooks
define('my-component', _ => (
...
...
), {
use: ['count', 'path.a', 'path[1].b'],
useSelf: ['path.c', 'path[1].d'],
compute: {
doubleCount() {
return this.count * 2
}
},
css: 'h1 { color: red; }',
propTypes: { },
defaultProps: { },
sLightDom: true, //default is false
//life cycle
install() { },
installed() { },
uninstall() { },
receiveProps() { },
beforeUpdate() { },
updated() { },
beforeRender() { },
rendered() { },
//custom methods
myMethodA() { },
myMethodB() { }
})Inject use or useSelf through prop
<my-counter use={['count']} ></my-counter>Ecosystem of Omi
💯Base
| Project | Description |
|---|---|
| omi-docs and codepen and webcomponents.dev | Omi official documents |
omix![]() |
小程序全局状态管理框架,数据触手可及,状态无处遁形 |
omim![]() |
Cross frameworks and themes components.(DOCS & REPL && JOIN US!) |
omi-kbone |
使用 omi + kbone 多端开发(小程序和Web)的贪吃蛇游戏。 |
| omio | Omi for old browsers with same api(IE8+) |
omiv |
1kb store system for Vue apps. SSR Now |
omis |
Omis + React |
| omi-ssr | Server-side rendering(support omio only) |
| omi-router | Omi official router in 1KB js |
| omi-cli | Project scaffolding. → Base Templates and → Other Templates |
| omi-devtools | Browser DevTools extension |
| omiu | Simple Omi UI |
| omil | Webpack loader for Omi.js components.(DOCS) |
| omi-snippets | A beautify VSCode extension for .omi or .eno file, Install now! |
| obaa or JSONPatcherProxy | Observe or Proxy any object's any change |
🐍Snake MVP
| Project | Description |
|---|---|
omi-snake & → Touch the demo |
The Snake-Eating Game Based on MVP Architecture Written by Omi |
omi-kbone-snake |
omi-kbone 写的 MVP 架构的跨端贪吃蛇游戏,支持小程序和 H5 |
| Preact-snake & → Touch the demo | The Snake-Eating Game Based on MVP Architecture Written by Preact + Preact-CSS + Omis |
| [P]react-snake & → Touch the demo | The Snake-Eating Game Based on MVP Architecture Written by React/Preact |
| vue-snake | The Snake-Eating Game Based on MVP Architecture Written by Vue + Omiv |
omix-snake![]() |
The Snake-Eating Game Based on MVP Architecture Written by Omix |
👍Mini Program(小程序)
| Project | Description |
|---|---|
omix![]() |
小程序全局状态管理框架,数据触手可及,状态无处遁形 |
react-kbone |
直接使用 React 开发小程序或 Web,基于 kbone |
preact-kbone |
直接使用 Preact 开发小程序或 Web,基于 kbone |
| omi-cloud | 小程序•云开发 |
| omip | 直接使用 Omi 开发小程序或 H5 SPA |
| mps | 原生小程序增强框架(JSX + Less 输出 WXML + WXSS),也支持 QQ 轻应用 |
| cax | 小程序 Canvas 和 SVG 渲染引擎 |
| omi-mp | 通过微信小程序开发和生成 Web 单页应用(H5 SPA) |
| westore | 小程序状态管理 |
| comi | 小程序代码高亮和 markdown 渲染组件 |
| wx-touch-event | 基于 AlloyFinger 改造的小程序手势解决方案 |
📚Other
| Project | Description |
|---|---|
omi-piano![]() |
Build piano with Omi and Omi Snippets, Enjoy now! |
| omi-chart | Simple HTML5 Charts using chart-x tag. |
| md2site | Static Site Generator with markdown powered by Omio. |
| omi-30-seconds | Useful Omi snippets that you can understand in 30 seconds. |
| omi-canvas | Perfect fusion of web components, jsx and canvas. |
| omi-swiper | Omi + Swiper |
| omi-vscode | VSCode extension for omi, Install now! |
| omi-ex | Omi.js extension(TypeScript) |
| omi-transform | Omi / css3transform integration. Made css3 transform super easy in your Omi project. |
| omi-finger | Support touch and gesture events in your Omi project. |
| omi-touch | Smooth scrolling, rotation, pull to refresh and any motion for the web. |
| omi-native | Render web components to native |
| omi-i18n | Internationalization solution for omi.js using i18next ecosystem |
| omi-page | Tiny client-side router by page |
| omie | Build cross platform desktop apps with Omi.js and Electron.js |
| omi-cv | Create a front-end engineer curriculum vitae, Get Started! |
| Soo | Has same API as omi but is great alternative if you want to create custom elements without JSX, virtual DOM and store |
| CEE | Fork from custom-elements-everywhere |
Why Omi?
- Tiny size and High performance
- Cross frameworks(react, preact, vue, angular), components of omi are pure custom elements
- One framework. Mobile & desktop & mini program
- Stateless View Architecture Design
- Be friendly to custom elements, you can pass
falseattributes to elements through string'0'or string'false', you can passobjectattributes to elements through:prefix andOmi.$ - Easy two way binding by extend api
- Supports TypeScript
- Reactive data-binding
- Native tap event support
- Having Cross-frameworks UI components - omim
- Excellent compatibility(IE8+) with omio
- Enhanced CSS, rpx unit support base on 750 screen width
- Compliance with browser trend and API design
- Merge Web Components, JSX into one framework
- Web Components can also be a data-driven view,
UI = fn(data). - JSX is the best development experience (code intelligent completion and tip) UI Expression with least grammatical noise and it's turing complete(template engine is not, es template string is but grammatical noise is too loud)
- Look at Facebook React vs Web Components,Omi combines their advantages and gives developers the freedom to choose the way they like
- Shadow DOM merges with Virtual DOM, Omi uses both virtual DOM and real Shadow DOM to make view updates more accurate and faster
- Scoped CSS's best solution is Shadow DOM, the community churning out frameworks and libraries for Scoped CSS (using JS or JSON writing styles such as Radium, jsxstyle, react-style; binding to webpack using generated unique
classNamefilename-classname-hash, such as CSS Modules, Vue), are hack technologies; and Shadow DOM Style is the perfect solution. - The original Path Updating store system. Proxy-based automatic accurate update, low power consumption, high degree of freedom, excellent performance, easy integration of
requestIdleCallback,It will automatically update UI partially when data is changed
Compare TodoApp by Omi and React, Omi and React rendering DOM structure:
| Omi | React | Omio |
|---|---|---|
![]() |
![]() |
![]() |
Omi uses Shadow DOM based style isolation and semantic structure.
Useful Resources
Contribution
Build a example:
npm start example_nameBuild omi:
npm run buildUnit testing
npm run testCore Maintainers
Please contact us for any questions.
Thanks
License
MIT © Tencent



