Giter VIP home page Giter VIP logo

Comments (1)

Jinjiang avatar Jinjiang commented on May 5, 2024

Updates:

/**
 * format comparison
 * _h(self, children)       -> render
 * _e(tag, data, namespace) -> self
 * _t(text)                 -> text content
 * _m(index)                -> static tree
 */

ref: vuejs/vue@6fe2688#commitcomment-17533656

New JS Bundle format design (compared with current Vue 2.0 format):

/**
 * format comparison
 *
 * old:
 * __h__(tag, data, children, namespace)
 * new:
 * __r__(self, children)       -> render
 * __s__(tag, data, namespace) -> self
 * __t__(text)                 -> text content
 * __m__(index)                -> static tree
 *
 * the new format MUST be with `stream: true` option from root Vm
 */
Vue.component('foo', {
  props: ['a', 'b'],
  data: function () {
    return {list: [1,2]}
  },
  render: function () {
    with (this) {
      // old format
      return __h__('div', undefined, [
        (list) && __renderList__((list), function (k, v,$index) {
          return __h__('div', {
            class:[a, 'a'],
            style:{m: '1', n: a},
            attrs:{"n":a},
            staticAttrs:{"m":"a","style":"l: 2"}
          }, [
            ("\n aaa"+__toString__(a)+"bbb"+__toString__(k)+"-"+__toString__(v)+"\n "),
            _staticTrees[0]
          ], '')
        })
      ], '')
      // // new format
      // return __r__(
      //   __s__('div', {
      //     staticAttrs: {a: 'b'}
      //   }),
      //   [
      //     __r__(
      //       __s__('text', {
      //         staticAttrs: {value: 'child text content'}
      //       })
      //     ),
      //   (list) && __renderList__((list), function(k, v, $index) {
      //     return __r__(
      //       __s__('div', {
      //         class:[a, 'a'],
      //         style:{m: '1', n: a},
      //         attrs:{"n":a},
      //         staticAttrs:{"m":"a","style":"l: 2"}
      //       }),
      //       [
      //         __t__("\n aaa"+__toString__(a)+"bbb"+__toString__(k)+"-"+__toString__(v)+"\n "),
      //         __m__(0)
      //       ]
      //     )
      //   })]
      // )
    }
  },
  staticRenderFns: [
    function () {
      with(this){
        // old format
        return __h__('text', {
          staticAttrs: {value: 'Hello World'}
        }, [], '')
        // // new format
        // return __r__(
        //   __s__('text', {
        //     staticAttrs: {value: 'Hello World'}
        //   }),
        //   []
        // )
      }
      with (this) {
      }
    }
  ]
})

return new Vue({
  el: 'scroller',
  data: {x: 1, y: 2, z: 'foo'},
  methods: {foo: function (e) {
    console.log('event', e)
    this.y++
  }},
  style: {y: {fontSize: 64}},
  // // new format
  // stream: true,
  render: function () {
    with (this) {
      // old format
      return __h__(
        'div', {},
        [
          __h__('foo', {attrs:{"a":x,"b":y}}, undefined, ''),
          __h__('text', {
            on:{"click":foo},
            staticClass:"a b",
            class:[y, 'y'],
            attrs:{value:(__toString__(y)+"asdfasdfaf")}
          }, [], '')
        ], ''
      )
      // // new format
      // return __r__(
      //   __s__('div', {}),
      //   [
      //     __r__(
      //       __s__('foo', {
      //         attrs:{"a":x,"b":y}
      //       }),
      //       []
      //     ),
      //     __r__(
      //       __s__('text', {
      //         on:{"click":foo},
      //         staticClass:"a b",
      //         class:[y, 'y'],
      //         attrs:{value:(__toString__(y)+"asdfasdfaf")},
      //         // append: true
      //       }),
      //       []
      //     )
      //   ]
      // )
    }
  }
})

// // testing registerModules()
// console.log(__weex_require_module__('dom'))

// // testing registerComponents()
// registerComponents(['a', {name: 'b'}, null])
// console.log(Vue.config.isReservedTag('a'))
// console.log(Vue.config.isReservedTag('b'))
// console.log(Vue.config.isReservedTag('c'))

from weex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.