0.6.6 • Published 5 years ago

komponentize v0.6.6

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Komponentize

Lightweight Frontend Componentization Based on Snabbdom. It's small, simple and easy to use.

Installation

Node.js

npm install komponentize

Browser

<script src="node_modules/komponentize/dist/komponentize.min.js"></script>

Quick Start

import Component from "komponentize";

class MyComponent extends Component {
  constructor(name) {
    super();
    this.name = name;
  }

  render() {
    return <div>Hello {this.name}!</div>;
  }
}

const myComponent = new MyComponent("John");
myComponent.connect(document.getElementById("app")); // 'Hello John!'

myComponent.name = "Jane";
myComponent.setState(); // 'Hello Jane!'

Features

  • Small: 5KB gzipped

  • Simple and easy to use: a component has a vnode, a render method and a setState method, that's all, almostly

Configurations

Babel

{
  "plugins": [
    [
      "transform-react-jsx",
      {
        "pragma": "Component.createElement"
      }
    ]
  ]
}

TypeScript

tsconfig.json

{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "Component.createElement"
  }
}

Then add a JSX.d.ts in your directory to suppress the errors on JSX.IntrinsicElements

declare namespace JSX {
  interface IntrinsicElements {
    [elemName: string]: any;
  }
}

Documentation

context

Component.context is a public namespace for sharing props and methods between components, you can access it directly or with setContext

componentInstance.setContext({ name: "komponentize" });
console.log(Component.context.name); // 'komponentize'

createElement

Component.createElement uses Snabbdom-pragma to produce vnodes

vnode

The vnode property is of type Snabbdom.VNode

render

The render: () => VNode method should be implemented by each component. To avoid "this binding issues", bind render to this is recommended

setState

Different from React, setState: () => void in komponentize takes no parameter

setContext

setContext: (ctx: { [key: string]: any }) => void

connect

connect: (el: HTMLElement) => void mount a component to an existing element.

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.1.12

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago