Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
hybrids
Advanced tools
Readme
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:
The project documentation is available at the hybrids.js.org site.
It's based on plain objects and pure functions1, 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>
You can read more in the Component Model section.
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`
<div>
${store.pending(user) && `Loading...`}
${store.error(user) && `Something went wrong...`}
${store.ready(user) && html`
<p>${user.firstName} ${user.lastName}</p>
`}
</div>
`,
});
<user-details user="2"></user-details>
You can read more in the Store section.
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",
content: () => html`
<template layout="column">
<h1>Home</h1>
<nav layout="row gap">
<a href="${router.url(Details)}">Details</a>
</nav>
...
</template>
`,
});
export define({
tag: "app-router",
stack: router(Home),
content: ({ stack }) => html`
<template layout="column">
${stack}
</template>
`,
});
<app-router></app-router>
You can read more in the Router section.
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",
content: () => html`
<template layout="column center gap:2">
<div layout="grow grid:1|max">
<h1>Home</h1>
...
</div>
<footer layout@768px="hidden">...</footer>
</template>
`
});
You can read more in the Layout Engine section of the documentation.
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`
<div>Hello ${name}!</div>
`,
});
localize("pl", {
"Hello ${0}!": {
message: "Witaj ${0}!",
},
});
You can read more in the Localization section of the documentation.
Do you need help? Something went wrong? Feel free to create an issue in the github repository or join the Gitter channel.
Hybrids is released under the MIT License.
Pure functions only apply to the component definition. Side effects attached to event listeners might mutate the host element. ↩
FAQs
A JavaScript framework for creating fully-featured web applications, components libraries, and single web components with unique declarative and functional architecture
The npm package hybrids receives a total of 1,286 weekly downloads. As such, hybrids popularity was classified as popular.
We found that hybrids demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.