javascript Superfine + class = SuperfineApp ref:https://qiita.com/tom-u/items/a2d7602d02320d1625d8

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Superfine + class = SuperfineApp ref:https://qiita.com/tom-u/items/a2d7602d02320d1625d8相关的知识,希望对你有一定的参考价值。

// import * as superfine from 'https://unpkg.com/superfine?module'
// const { h } = superfine;
//
// const view = count =>
//   h('div', {}, [
//     h('h1', {}, count),
//     h('button', { onclick: () => render(count - 1) }, '-'),
//     h('button', { onclick: () => render(count + 1) }, '+')
//   ])
//
// const mount = (view, container, node) => state => {
//   node = superfine.patch(node, view(state), container)
// }
//
// const render = mount(view, document.body)
//
// render(0)

import * as superfine from 'https://unpkg.com/superfine?module'
const { h } = superfine;

class SuperfineApp {
  constructor(container, state, view) {
    this.container = container;
    this.state = state;
    this.view = view;
    this.mount().render();
  }

  mount() {
    let node;
    this.render = () => {
      node = superfine.patch(node, this.view(this), this.container);
      return this;
    }
    return this;
  }
}

// new SuperfineApp(document.body, 0, app =>
//   h('div', {}, [
//     h('h1', {}, app.state),
//     h('button', { onclick: () => { app.state--; app.render() } }, '-'),
//     h('button', { onclick: () => { app.state++; app.render() } }, '+'),
//   ])
// );

class CounterApp extends SuperfineApp {
  add(by=1) {
    this.state += by;
    return this.render();
  }
  sub(by=1) {
    this.state -= by;
    return this.render();
  }
}

new CounterApp(document.body, 0, app =>
  h('div', {}, [
    h('h1', {}, app.state),
    h('button', { onclick: () => app.sub() }, '-'),
    h('button', { onclick: () => app.add() }, '+'),
  ])
);
class SuperfineApp {
  constructor(container, state, view) {
    this.state = state;
    let node;
    this.render = () => {
      node = patch(node, view(this), container);
      return this;
    };
  }
}

以上是关于javascript Superfine + class = SuperfineApp ref:https://qiita.com/tom-u/items/a2d7602d02320d1625d8的主要内容,如果未能解决你的问题,请参考以下文章

html superfine + class = Ultrapp ref:https://qiita.com/tom-u/items/094d712c33f4a5cb9b79

javascript 导出Netflix的“我的列表”,“观看历史记录”以及竖起/缩小或评级。 Netflix评级与脚本输出的屏幕截图:https://cl.ly/4e15

JavaScript 笔试题

如何转换字符串? [复制]

是否可以从 golang 结构返回 javascript 函数?

JavaScript——面向对象原型继承与class继承