Hybrids

Extraordinary JavaScript UI framework with unique declarative and functiona...

README


npm version build status coverage status

hybrids is a JavaScript UI framework for creating fully-featured web applications, components libraries, or single web components with unique mixed declarative and functional architecture.

The main goal of the framework is to provide a complete set of tools for the web platform - everything without external dependencies. It supports building UI components, managing complex states, creating app flows with client-side routing, and localizing its content for the worldwide markets. All of the parts follow the same unique concepts making it easy to understand and use!

Quick Look


The Simplest Structure


The component model is based on plain objects and pure functions*, still using the Web Components API under the hood:

  1. ``` js
  2. import { html, define } from "hybrids";
  3.   
  4. function increaseCount(host) {
  5.   host.count += 1;
  6. }

  7. export default define({
  8.   tag: "simple-counter",
  9.   count: 0,
  10.   render: ({ count }) => html`
  11.     <button onclick="${increaseCount}">
  12.       Count: ${count}
  13.     </button>
  14.   `,
  15. });
  16. ```

  1. ``` html
  2. <simple-counter count="42"></simple-counter>
  3. ```
[![Edit web component built with hybrids library](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/simple-counter-web-component-built-with-hybrids-library-co2ow?file=/src/SimpleCounter.js)

\* Pure functions only apply to the component definition. Side effects attached to event listeners might mutate the host element.

You can read more in the Component Model section of the documentation.

Seamless Localization


Built-in support for automatic translation of the component's content makes translation seamless and easy to integrate. Additionally, the framework provides a way to add dynamic messages with plural forms, HTML content, or use messages outside of the template context. Also, it comes with handy CLI tool to extract messages from the source code!

  1. ``` js
  2. import { define, html, localize } from "hybrids";

  3. export default define({
  4.   tag: "my-element",
  5.   name: "",
  6.   render: ({ name }) => html`
  7.     <div>Hello ${name}!</div>
  8.   `,
  9. });

  10. localize("pl", {
  11.   "Hello ${0}!": {
  12.     message: "Witaj ${0}!",
  13.   },
  14. });
  15. ```

You can read more in the Localization section of the documentation.

Complex State Management


The store module provides a global state management based on declarative model definitions with built-in support for async external storages, relations, offline caching, and many more. It follows the declarative architecture to simplify the process of defining and using data structures:

  1. ``` js
  2. import { define, store, html } from "hybrids";

  3. const User = {
  4.   id: true,
  5.   firstName: "",
  6.   lastName: "",
  7.   [store.connect] : {
  8.     get: id => fetch(`/users/${id}`).then(res => res.json()),
  9.   },
  10. };

  11. define({
  12.   tag: "my-user-details",
  13.   user: store(User),
  14.   render: ({ user }) => html`
  15.     <div>
  16.       ${store.pending(user) && `Loading...`}
  17.       ${store.error(user) && `Something went wrong...`}

  18.       ${store.ready(user) && html`
  19.         <p>${user.firstName} ${user.lastName}</p>
  20.       `}
  21.     </div>
  22.   `,
  23. });
  24. ```

  1. ``` html
  2. <my-user-details user="2"></my-user-details>
  3. ```

You can read more in the Store section of the documentation.

Structural Client-Side Routing


The router module provides a global navigation system for client-side applications. Rather than just matching URLs with the corresponding components, it depends on a tree-like structure of views, which have their own routing configuration in the component definition. It makes the URLs optional, have out-the-box support for dialogs, protected views, and many more.

  1. ``` js
  2. import { define, html, router } from "hybrids";

  3. import Home from "./views/Home.js";

  4. export define({
  5.   tag: "my-app",
  6.   views: router(Home),
  7.   content: ({ views }) => html`
  8.     <my-app-layout>
  9.       ${views}
  10.     </my-app-layout>
  11.   `,
  12. });
  13. ```

  1. ``` html
  2. <my-app></my-app>
  3. ```

You can read more in the Router section of the documentation.

Documentation


The project documentation is available at the hybrids.js.org site.

Community


Follow on Twitter
Chat on Gitter

License


hybrids is released under the MIT License.