2.0.3 • Published 4 months ago

paintor v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Paintor

Static Badge Static Badge

npm version npm package minimized gzipped size npm downloads npm type definitions test license

A JavaScript library with component-based model for building reactive client-side user interfaces or generating HTML code.

Why? Because JavaScript is good enough. So good, in fact, that even HTML can be written in JavaScript.

Documentation and Examples

Key Features

  • JavaScript syntax: The code you write is the code to run
  • No dependencies
  • No Virtual DOM: Reactivity is achieved through Proxy and DOM events
  • Templates in JavaScript or HTML (experimental): JavaScript HTML-like tree structure (HyperScript) or HTML syntax in template literals
  • Scoped CSS: Each component can have its own style
  • Observers: Receive events on state changes
  • Server-Side Rendering (SSR): Generate HTML code on the server
  • Internationalization (i18n)
  • Type definitions: Built-in TypeScript definitions for code completion and type safety

Quick Examples

Clicks counter

import { css, compose, state, template } from 'paintor'

// Component
function Counter(/* Props */ { buttonText }) {
  // Scoped CSS
  css`
    div {
      span {
        color: blue;
      }
    }
  `

  // Template
  return template((x) => {
    // Local state
    const counter = state({ clicks: 0 })

    // HTML elements
    x.div(
      x.button(
        { onClick: () => counter.clicks++ },
        buttonText
      ),
      x.span(() => counter.clicks)
    )

    // Observe state changes
    on(counter.clicks).change((event) => {
      console.log(`Clicked ${event.value} times`)
    })
  })
}

// Render
const app = compose(
  Counter({ buttonText: 'Click me' })
)
app.paint('#app')

Generate HTML code (for Server-Side Rendering)

// To generate HTML code, instead of paint(), use html()
const htmlCode = app.html()

Observe state changes

import { state, on } from 'paintor'

// Create state
const myState = state({ count: 0 })

// Make state changes
setInterval(() => {
  myState.count++
}, 1000)

// Observe state changes
on(myState.count).change((data) => {
  console.log(data.value)
})

// The result in the console will be:
// 1
// 2
// 3
// ...

Performance

Paintor is faster than React in many aspects, and slower than Svelte, Vue and Angular.

js-framework-benchmark-comparison

1.4.6

6 months ago

1.4.5

6 months ago

1.4.4

6 months ago

1.4.3

7 months ago

1.4.2

8 months ago

1.4.1

8 months ago

2.0.3

4 months ago

2.0.2

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.4.0

9 months ago

1.3.10

9 months ago

1.3.9

11 months ago

1.3.7

11 months ago

1.3.6

1 year ago

1.3.8

11 months ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.0

1 year ago

0.0.2

4 years ago

0.0.1

4 years ago