MCPcopy
hub / github.com/hybridsjs/hybrids

github.com/hybridsjs/hybrids @v9.1.22 sqlite

repository ↗ · DeepWiki ↗ · release v9.1.22 ↗
282 symbols 717 edges 60 files 0 documented · 0%
README

hybrids

build status coverage status npm version

An extraordinary JavaScript framework for creating client-side web applications, UI components libraries, or single web components with unique mixed declarative and functional architecture

Hybrids provides a complete set of features for building modern web applications:

  • Component Model based on plain objects and pure functions
  • Global State Management with external storages, offline caching, relations, and more
  • App-like Routing based on the graph structure of views
  • Layout Engine making UI layouts development much faster
  • Localization with automatic translation of the templates content
  • Hot Module Replacement support without any additional configuration

Documentation

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

Quick Look

Component Model

It's based on plain objects and pure functions[^1], still using the Web Components API under the hood:

import { html, define } from "hybrids";

function increaseCount(host) {
  host.count += 1;
}

export default define({
  tag: "simple-counter",
  count: 0,
  render: ({ count }) => html`
    <button onclick="${increaseCount}">
      Count: ${count}
    </button>
  `,
});
<simple-counter count="42"></simple-counter>

Open in StackBlitz

You can read more in the Component Model section.

Global State Management

A global state management uses declarative model definitions with support for async external storages, relations, offline caching, and many more:

import { define, store, html } from "hybrids";

const User = {
  id: true,
  firstName: "",
  lastName: "",
  [store.connect] : {
    get: id => fetch(`/users/${id}`).then(...),
  },
};

define({
  tag: "user-details",
  user: store(User),
  render: ({ user }) => html`



      ${store.pending(user) && `Loading...`}
      ${store.error(user) && `Something went wrong...`}

      ${store.ready(user) && html`


${user.firstName} ${user.lastName}


      `}



  `,
});
<user-details user="2"></user-details>

You can read more in the Store section.

App-like Routing

Rather than just matching URLs with the corresponding components, the router depends on a tree-like structure of views, which have their own routing configuration. It makes the URLs optional, have out-the-box support for dialogs, protected views, and many more.

import { define, html, router } from "hybrids";

import Details from  "./details.js";

const Home = define({
  [router.connect]: { stack: [Details, ...] },
  tag: "app-home",
  render: () => html`
    <template layout="column">
      <h1>Home</h1>
      <nav layout="row gap">
        <a href="https://github.com/hybridsjs/hybrids/raw/v9.1.22/${router.url(Details)}">Details</a>
      </nav>
      ...
    </template>  
  `,
});

export define({
  tag: "app-router",
  stack: router(Home),
  render: ({ stack }) => html`
    <template layout="column">
      ${stack}
    </template>
  `,
});
<app-router></app-router>

You can read more in the Router section.

Layout Engine

Create CSS layouts in-place in templates, even without using Shadow DOM, but still keeping the encapsulation of the component's styles:

define({
  tag: "app-home-view",
  render: () => html`
    <template layout="column center gap:2">



        <h1>Home</h1>
        ...




      <footer layout@768px="hidden">...</footer>
    </template>
  `
});

You can read more in the Layout Engine section of the documentation.

Localization

The library supports automatic translation of the component's content, which makes translation seamless and easy to integrate. Additionally, it 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!

import { define, html, localize } from "hybrids";

export default define({
  tag: "my-element",
  name: "",
  render: ({ name }) => html`


Hello ${name}!


  `,
});

localize("pl", {
  "Hello ${0}!": {
    message: "Witaj ${0}!",
  },
});

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

Community

Do you need help? Something went wrong? Feel free to create an issue in the github repository or join the Gitter channel.

License

Hybrids is released under the MIT License.

[^1]: Pure functions only apply to the component definition. Side effects attached to event listeners might mutate the host element.

Extension points exported contracts — how you extend this code

Descriptor (Interface)
(no doc)
types/index.d.ts
IOtherModel (Interface)
(no doc)
test/types/store/ref.ts
UpdateFunction (Interface)
(no doc)
types/index.d.ts
IEnumerableModel (Interface)
(no doc)
test/types/store/ref.ts
RenderFunction (Interface)
(no doc)
types/index.d.ts
ISingleton (Interface)
(no doc)
test/types/store/singleton-definition.store.ts
RenderDescriptor (Interface)
(no doc)
types/index.d.ts
IEnumerableModel (Interface)
(no doc)
test/types/store/descriptor.ts

Core symbols most depended-on inside this repo

html
called by 190
src/template/index.js
define
called by 121
src/define.js
render
called by 116
test/spec/html.js
resolveTimeout
called by 113
test/helpers.js
get
called by 64
test/spec/store.js
resolveRaf
called by 58
test/helpers.js
hybrids
called by 56
test/spec/router.js
store
called by 45
src/store.js

Shape

Function 249
Interface 21
Class 6
Method 6

Languages

TypeScript100%

Modules by API surface

src/store.js46 symbols
src/router.js39 symbols
cli/utils/sax.js28 symbols
test/spec/html.js20 symbols
src/cache.js12 symbols
types/index.d.ts11 symbols
src/define.js10 symbols
src/template/core.js8 symbols
cli/extract/task.js8 symbols
test/spec/cache.js7 symbols
src/localize.js7 symbols
src/utils.js6 symbols

Dependencies from manifests, versioned

eslint8.7.0 · 1×
eslint-config-prettier9.1.0 · 1×
eslint-plugin-import2.25.4 · 1×
jasmine-core5.6.0 · 1×
karma6.4.4 · 1×
karma-chrome-launcher3.1.0 · 1×
karma-coverage2.1.0 · 1×
karma-firefox-launcher2.1.2 · 1×
karma-jasmine5.1.0 · 1×
karma-webkit-launcher2.1.0 · 1×
playwright1.50.1 · 1×

For agents

$ claude mcp add hybrids \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact