0.6.6 • Published 7 years ago

komponentize v0.6.6

Weekly downloads
1
License
MIT
Repository
github
Last release
7 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

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.6

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.6

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.1.12

10 years ago

0.1.11

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago