Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Hybrids is a UI library for creating Web Components, which favors plain objects and pure functions over class
and this
syntax. It provides simple and functional API for creating custom elements.
Install npm package:
npm i hybrids
Then, import required features and define a custom element:
import { html, define } from 'hybrids';
export function increaseCount(host) {
host.count += 1;
}
export const SimpleCounter = {
count: 0,
render: ({ count }) => html`
<button onclick="${increaseCount}">
Count: ${count}
</button>
`,
};
define('simple-counter', SimpleCounter);
👆 Click and play on ⚡StackBlitz
Finally, use your custom element in HTML:
<simple-counter count="10"></simple-counter>
You can also use the built version from unpkg.com CDN (with window.hybrids
global namespace):
<script src="https://unpkg.com/hybrids@[PUT_VERSION_HERE:x.x.x]/dist/hybrids.js"></script>
There are some common patterns among JavaScript UI libraries like class syntax, complex lifecycle or stateful architecture. What can we say about them?
Classes can be confusing, especially about how to use this
, binding or super()
calls. They are also hard to compose. Complex lifecycle callbacks have to be studied to understand very well. A stateful approach can open doors for difficult to maintain, imperative code. Is there any way out from all of those challenges?
After all, class syntax in JavaScript is only sugar on top of the constructors and prototypes. Because of that, we can switch the component structure to a map of properties applied to the prototype of the custom element class constructor. Lifecycle callbacks can be minimized with smart change detection and cache mechanism. Moreover, they can be implemented independently in the property scope rather than globally in the component definition.
With all of that, the code may become simple to understand, and the code is written in a declarative way. Not yet sold? You can read more in the Core Concepts section of the project documentation.
The hybrids documentation is available at hybrids.js.org or in the docs path of the repository:
The library requires some of the ES2015 APIs and Shadow DOM, Custom Elements, and Template specifications. You can use hybrids
in all evergreen browsers and IE11 including a list of required polyfills and shims. The easiest way is to add bundle from @webcomponents/webcomponentsjs
package on top of your project:
import '@webcomponents/webcomponentsjs/webcomponents-bundle.js';
import { define, ... } from 'hybrids';
...
The polyfill package provides two modes in which you can use it (webcomponents-bundle.js
and webcomponents-loader.js
). Read more in the How to use section of the documentation.
Web components shims have some limitations. Especially, webcomponents/shadycss
approximates CSS scoping and CSS custom properties inheritance. Read more on the known issues and custom properties shim limitations pages.
hybrids
is released under the MIT License.
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,572 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 0 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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.