项目作者: briefjs

项目描述 :
Deadly simple declarative JavaScript framework for building UI.
高级语言: JavaScript
项目地址: git://github.com/briefjs/briefjs.git
创建时间: 2018-12-21T03:31:06Z
项目社区:https://github.com/briefjs/briefjs

开源协议:

下载


BriefJS

Deadly simple declarative JavaScript framework for building UI.

Why BriefJS?

  • Tiny size. (< 3kb gzipped)
  • Zero dependence.
  • Pure ES6.
  • No compiler. (Directly use taged template strings).
  • Stateless.
  • Fast and extendable.

Installation

From CDN:

  1. <script src="https://unpkg.com/briefjs/dist/brief.min.js"></script>

With NPM:

  1. npm install briefjs

Example

  1. const {tags, component, render} = briefjs;
  2. const {div, span} = tags;
  3. function randomColor() {
  4. const r = Math.round(Math.random() * 255);
  5. const g = Math.round(Math.random() * 255);
  6. const b = Math.round(Math.random() * 255);
  7. return `rgb(${r},${g},${b})`;
  8. }
  9. const MyTag = component({
  10. props: {
  11. color: 'red;',
  12. onclick: 'void(0)',
  13. },
  14. render(props, slot) {
  15. return div({style: {color: props.color}, onclick: props.onclick})`
  16. ${span({ref: 'foo'})`1`}
  17. ${span`${props.color}`}
  18. ${slot}
  19. `;
  20. },
  21. updated() {
  22. console.log(this.refs);
  23. },
  24. });
  25. const Outer = component({
  26. render(props, slot) {
  27. let color = randomColor();
  28. const onclick = () => {
  29. color = randomColor();
  30. this.update();
  31. };
  32. return MyTag({color, onclick})`${slot}`;
  33. },
  34. updated() {
  35. this.node.addEventListener('mousedown', () => {
  36. console.log('mousedown');
  37. });
  38. },
  39. });
  40. const tpl = div`
  41. ${Outer`
  42. ${span`abc`}
  43. `}
  44. ${span`3`}
  45. ${span`4`}
  46. ${div`
  47. ${span`5`}
  48. `}
  49. `;
  50. render(tpl, document.getElementById('app'));