omi

Web Components Framework - Web组件框架

OTHER License

Downloads
8.7K
Stars
13K
Committers
15

Bot releases are hidden (Show)

omi -

Published by dntzhang about 1 month ago

omi -

Published by dntzhang about 2 months ago

omi - Latest Release

Published by dntzhang 8 months ago

omi -

Published by dntzhang 9 months ago

omi - Function component is supported! 🎉

Published by dntzhang 9 months ago

function ChildComponent(props) {
  return (
    <span>{props.msg}</span>
  )
}

class ParentComponent extends Component {
  render() {
    return (
      <div>
        <ChildComponent msg="omi" />
      </div>
    )
  }
}
import { tag, Component, h, bind } from 'omi'

@tag('my-counter')
class MyCounter extends Component {
  static props = {
    count: {
      type: Number,
      default: 0,
      changed(newValue, oldValue) {
        this.state.count = newValue
        this.update()
      }
    }
  }

  state = {
    count: null
  }

  install() {
    this.state.count = this.props.count
  }

  @bind
  sub() {
    this.state.count--
    this.update()
    this.fire('change', this.state.count)
  }

  @bind
  add() {
    this.state.count++
    this.update()
    this.fire('change', this.state.count)
  }

  render() {
    return (
      <>
        <button onClick={this.sub}>-</button>
        <span>{this.state.count}</span>
        <button onClick={this.add}>+</button>
      </>
    )
  }
}
omi - Using constructor as tag name

Published by dntzhang 10 months ago

import { Button } from './button' 

class MyApp extends Component {
  render() {
    return (
      <Button>test</Button>
    )
  }
}
omi -

Published by dntzhang 10 months ago

omi - Lazy definition

Published by dntzhang 11 months ago

If we are writing a component library and need to use tree shaking capabilities,

import { WeButton } from 'ui-lib' 

It could lead to definition failure if Button is not used, as it would be tree-shaken away. Therefore, we need to use Button, for example,

WeButton.define('we-button')
omi -

Published by dntzhang 11 months ago

omi -

Published by dntzhang 11 months ago

omi -

Published by dntzhang 12 months ago

omi -

Published by dntzhang 12 months ago

omi - Support for injecting lifecycle into props🎉

Published by dntzhang 12 months ago

<my-el onInstalled={e => console.log('installed')}><my-el>
omi - Directive 🎉

Published by dntzhang 12 months ago

For Example:

Register AutoAnimate Directive:

import { registerDirective } from 'omi'
import autoAnimate from '@formkit/auto-animate'

registerDirective('auto-animate', autoAnimate)

Using Directive:

import { render, signal, tag, Component, h } from 'omi'

const show = signal(false)

@tag('my-app')
export class MyApp extends Component {
  render() {
    return (
      <>
        <buttton onClick={() => show.value = !show.value}>Toggle show</buttton>
        <div o-auto-animate >
          {show.value && <h2>Hello o-auto-animate!</h2>}
        </div>
      </>

    )
  }
}

render(<my-app />, document.body)
omi - Preventing tree shaking

Published by dntzhang 12 months ago

import { Button } from './button' // tree shaking
import './button' // will not tree shaking

class MyApp extends Component {
  render() {
    return (
      <o-button>test</o-buttom>
    )
  }
}
import { Button } from './button' 

class MyApp extends Component {
  render() {
    return (
      {/* will not tree shaking*/ }
      <Button.tagName>test</Button.tagName>
    )
  }
}
omi -

Published by dntzhang 12 months ago

omi -

Published by dntzhang 12 months ago

omi -

Published by dntzhang 12 months ago

Package Rankings
Top 1.45% on Npmjs.org
Top 3.63% on Proxy.golang.org