Skip to content

Releases: Tencent/omi

v4.0.22

07 Nov 14:13
Compare
Choose a tag to compare
  • [Fix] render array

Example >

v4.0.21

07 Nov 00:13
Compare
Choose a tag to compare
  • [Fix] Repairing multiple data changing leads to recursive render

noSlot support and fix render array

06 Nov 02:10
Compare
Choose a tag to compare

noSlot

For writing OMI plugins, noSlot is very useful. He will not insert redundant DOM into HTML and you can get the vdom in the plugin by props.children.

import { define, render, WeElement } from 'omi'

define('fancy-tabs', class extends WeElement {
  static noSlot = true

  render() {
    return [
      <div id="tabs">
        <slot id="tabsSlot" name="title" />
      </div>,
      <div id="panels">
        <slot id="panelsSlot" />
      </div>,
      <div>Show me only when noSlot is true!</div>
    ]
  }
})

define('my-app', class extends WeElement {
  render() {
    return (
      <div>
        <fancy-tabs>
          <button slot="title">Title</button>
          <button slot="title" selected>
            Title 2
          </button>
          <button slot="title">Title 3</button>
          <section>content panel 1</section>
          <section>content panel 2</section>
          <section>content panel 3</section>
        </fancy-tabs>
      </div>
    )
  }
})

render(<my-app />, 'body')

defaultProps and Component support

05 Nov 01:44
Compare
Choose a tag to compare
  • WeElement and Component are the same.
  • Supports defaultProps
define('my-first-element', class extends WeElement {
  static defaultProps = {
		name: 'Omi',
		myAge: 18
	}

  render(props) {
    return (
      <h1>Hello, {props.name}! Age {props.myAge}</h1>
    )
  }
})

Supports useCss in pure function element

03 Nov 13:18
Compare
Choose a tag to compare
v4.0.18

omi v4.0.18 - supports useCss

Add props and data args in pure element.

02 Nov 23:19
Compare
Choose a tag to compare
define('todo-list', function(props, data) {
  return (
    <ul>
      {props.items.map(item => (
        <li key={item.id}>{item.text}</li>
      ))}
    </ul>
  )
})

Simple checking for updating of observe element

01 Nov 10:08
Compare
Choose a tag to compare

https://github.com/Tencent/omi/blob/master/packages/omi/src/observe.js#L14-L20

It should be noted that if observe is used, do not set the value of data in some of the following functions: some complex objects such as obj or arr:

  • render
  • beforeRender
  • beforeUpdate
  • afterUpdate

Because data settings will simply compare the value before and after, complex objects will not be deep contrast, the contrast value will trigger different update, update will trigger the above function, infinite recursion.

But you set the property of data as a simple value type(string, number, bool ...)in those functions.

useData support

31 Oct 11:45
Compare
Choose a tag to compare
import { define, render } from 'omi'

define('my-counter', function() {
  const [count, setCount] = this.useData(0)

  return (
    <div>
      <button onClick={() => setCount(count - 1)}>-</button>
      <span>{count}</span>
      <button onClick={() => setCount(count + 1)}>+</button>
    </div>
  )
})

render(<my-counter />, 'body')

react hooks like support

31 Oct 09:17
Compare
Choose a tag to compare
import { define, render } from 'omi'

define('my-counter', function() {
  const [count, setCount] = this.use({
    data: 0,
    effect: function() {
      document.title = `The num is ${this.data}.`
    }
  })

  const [items, setItems] = this.use({
    data: [{ text: 'Omi' }],
    effect: function() {
      console.log(`The items count is ${this.data.length}.`)
    }
  })

  return (
    <div>
      <button onClick={() => setCount(count - 1)}>-</button>
      <span>{count}</span>
      <button onClick={() => setCount(count + 1)}>+</button>

      <ul>
        {items.map(item => {
          return <li>{item.text}</li>
        })}
      </ul>
      <button onClick={() => setItems([...items, { text: 'new item' }])}>
        add
      </button>
      <button onClick={() => setItems([])}>empty</button>
    </div>
  )
})

render(<my-counter />, 'body')

Observe elements are defined in a cleaner way

29 Oct 23:06
Compare
Choose a tag to compare
import { render, WeElement, define } from 'omi'

define('my-counter', class extends WeElement {
    static observe = true
    
    data = {
      count: 1
    }

    sub = () => {
      this.data.count--
    }

    add = () => {
      this.data.count++
    }

    render() {
      return (
        <div>
          <button onClick={this.sub}>-</button>
          <span>{this.data.count}</span>
          <button onClick={this.add}>+</button>
        </div>
      )
    }
  })

render(<my-counter />, 'body')