ランキングに戻る

slimjs/slim.js

CSSslimjs.com

Fast & Robust Front-End Micro-framework based on modern standards

webcomponentsdata-bindinges6domlifecyclejavascriptlibraryslimjsfront-endfront-end-developmentframeworkangular
スター成長
スター
1k
フォーク
61
週間成長
Issue
5
5001k
2016年12月2020年2月2023年5月2026年7月
成果物npmnpm install slim.js
README

hello, slim.js

Build Status

Chat on gitter

Hello slim.js - your declarative web components library

import { Slim } from 'slim-js';
import { tag, template } from 'slim-js/decorators';

@tag('my-awesome-element')
@template(`
<button @click="this.inc()"> + </button>
<span>{{this.count}}</span>
<button @click="this.dec()"> - </button>
`)
class extends Slim {
  count = 0;
  inc() { this.count++ }
  dec() { this.count-- }
}

Read the documentation

Slim is an ultra fast, native and elegant library for Web Components development

It's fast. Very fast.

Super fast. It leverages the native browser's API to manipulate DOM using templates, with custom directives. Imagine vue or angular's strctured templates combined with react's ease of use - combined, faster and lighter.

What's the difference? Why slim.js?

It's native. It has no black magic, no compilers and no external dependencies. It aims for fast performance, low CPU usage, using the native HTMLElement class inheritence and CustomElementsRegistry.

It works anywhere. You can combine slim.js in any other framework, combine any framework into slim.js app or any other combination.

You can write fully functional classes with complex code, or create pure "render-only" components without writing a single function.

Opt-in/Opt-out anything. The core is super small (2927 bytes gzipped), every directive is a self-contained module. Opt-in if you like. Pick your preferences for using (or not) shadow-dom. Work directly with properties on the element or create a view-model layer.

It's super easy to learn. Anything in your template that is wrapped with bars (example: <div>{{ this.user.name }}</div> ) is the actual code running. And it runs only when the used properties change. Changes affects only the specific DOM nodes that are bound. It means you can manipulate DOM manually without bothering the core, and vice-versa. No virtual dom engine or anything like that.

What about bundling, typescript, or other tools?

It just works. The library is written in javascript, and it has index.d.ts to support strongly-typed projects. It also provides access to it's internals, if you want to hack things out.

What are "directives" anyway?

Directives are middlewares that executes code on your template whenever you have attributes in your markup. For example, if you opt-in for the property-directive, any attribute that starts with a period (i.e. <some-element .user="{{this.user}}"></some-element>) will trigger the property-directive into action: this.user will project as a user property into some-element. Another example is the foreach-directive: You can map arrays or iterables to repeating elements. For example

<ul>
  <li *foreach="{{this.users.slice(0, 50)}}">
    <img src="{{item.picture}}" />
    <span class="user-name">{{item.name}}</span>
  </li>
</ul>

slim.js provides the following out-of-the-box directives:

  • custom-code (default)<form disabled="{{this.isFormReady(this.data)}}">...</form> or <div style="{{this.getStyleFor(this.user)}}">Welcome, {{this.user.name}}!</div>
  • property <img .src="{{this.imageSource}}">
  • events <input @change="this.handleInputChange(event)">
  • if <div *if="{{!this.isLoaded}}" class="spinner">Loading...</div>
  • foreach <li *foreach="{{this.someArray}}">{{item.value}}</li>
  • reference <form #ref="myForm">...</form> will create a property targeting the DOM element
  • repeat (optional, faster, with lazy memory release) <li *repeat>

All the directives (excluding custom-code) are optional - each is a standalone module. Choose the directives you use, or write your own!

What about plugins?

You can hook into any slim.js component's lifecycle using plugins. You plugin will be notified for step of the lifecycle, so you can add you own custom code or change things on-the-go.

Isn't a runtime library slower than compiled libraries?

Well, slim.js is an exception. Your custom code is memoized, and every piece of in-template code is created only once, can be even shared accross components. The core is very small and efficient, and releasing bound nodes is done progressively as background-tasks, keeping the user interface responsive as first priority. Modern browsers supports requestIdleCallback, so if supported, the removed elements will be released slowly and progressively.

Is this another framework?

Yes, and No. It's a very thin, fast, and extensible core library for writing custom-elements, powered by optional plugins and directives. You have the power to decide. It adds the firepower of a framework to your web-components, using the browser's native capabilities — as defined by W3C standards.

Here's what you get:

  • HTML markup with custom inlined code.
  • Reactive components: If a property is in the template, it becomes reactive. The core wraps it with a getter and setter function (and keeping your original one intact, if exists). No need to declare, it's derived from the tempalte.
  • Data binding: data changes triggers changes in the rendered HTML.
  • Directive system: Register your own directives.
  • Plugins: Add global lifecycle hooks for every slim.js component.
  • It feels like a framework (in a good way), but without the limits of a classic framework. It works everywhere, you can pick your own framework.
  • Low-footprint: it's less than 3KB gzipped. Directives are optional.
  • Single file for core functionality, and you're good to go.
  • No dependencies, everything is based on native browsers' API. Choose your own tools.
  • (Optional) Decorators for ES7/Next syntax, via Babel included.
  • Works with mixins from other component libraries, such as Polymer, out of the box.

Standards-compliant

  • ES6
  • Web Components V1
  • No transpiling or compilation required

No Setup required. It just works.

Use native (or bundlers) import statements, load from the CDN, or use the non-module (commonJS) file.

Documentation

The official website is built with Slim.js (with source maps). Check out the source code, see it for yourself.

Migration from older versions

Version 3 introduced the plugins.

Version 4 introduced the es modules.

Version 5 has new engine, directive system and plugin system.

es modules

import { Slim } from 'slim-js';

IIFE (no-modules)

<script src="slim-js/dist/index.legacy.js"></script>

Access a global Slim object.

HTML + Modules

<script type="module" src="slim-js/dist/index.js"></script>

Contibutors are welcome.

USE THE PLATFORM

Would you like to spend some good money on a good library and support the project? Contact eavichay@gmail.com.

関連リポジトリ
ionic-team/ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.

TypeScriptnpmMIT Licenseionicmobile
ionicframework.com
52.6k13.3k
ionic-team/ionicons

Premium hand-crafted icons built by Ionic, for Ionic apps and web apps everywhere 🌎

TypeScriptnpmMIT Licenseioniconsicons
ionicons.com
18.1k2.1k
riot/riot

Simple and elegant component-based UI library

JavaScriptnpmOtherjavascriptwebcomponents
riot.js.org
14.9k953
shoelace-style/shoelace

Shoelace is now Web Awesome. Come see what’s new!

TypeScriptnpmMIT Licensewebcomponentsux
webawesome.com
13.9k922
Tencent/omi

Web Components Framework - Web组件框架

TypeScriptnpmOtheromijsx
omi.cdn-go.cn
13.3k1.3k
ionic-team/stencil

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.

TypeScriptnpmwebcomponentscustom-elements
stenciljs.com
12.7k792
rough-stuff/wired-elements

Collection of custom elements that appear hand drawn. Great for wireframes or a fun look.

TypeScriptnpmMIT Licensewebcomponentslit-element
wiredjs.com
10.8k339
OnsenUI/OnsenUI

Mobile app development framework and SDK using HTML5 and JavaScript. Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, React and Vue.js.

JavaScriptnpmonsen-uicordova
onsen.io
8.9k998
BuilderIO/builder

Visual Development for React, Vue, Svelte, Qwik, and more

TypeScriptnpmMIT Licensereactwebcomponents
builder.io
8.8k1.2k
google/model-viewer

Easily display interactive 3D models on the web and in AR!

TypeScriptnpmApache License 2.03d-modelsgltf
modelviewer.dev
8.2k941
jd-opensource/micro-app

A simple, efficient and powerful micro front-end framework. 一款简约、高效、功能强大的微前端框架

CSSnpmMIT Licensejavascriptmicro-frontend
jd-opensource.github.io/micro-app/
6.2k639
GoogleChrome/rendertron

A Headless Chrome rendering solution

TypeScriptnpmApache License 2.0renderingheadless-chrome
render-tron.appspot.com
6k901