All Projects → bikeshaving → Crank

bikeshaving / Crank

Licence: mit
Write JSX-driven components with functions, promises and generators.

Programming Languages

typescript
32286 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Crank

Tomorrowland
Lightweight Promises for Swift & Obj-C
Stars: ✭ 106 (-95.74%)
Mutual labels:  promises, framework
Vcomponents
VComponents is a SwiftUI framework that contains 40+ customizable UI components
Stars: ✭ 117 (-95.3%)
Mutual labels:  framework, components
Atlas.js
A component-based Node.js library to reduce boilerplate and provide sane project structure 🍻
Stars: ✭ 108 (-95.66%)
Mutual labels:  framework, components
Kit
Tools for developing, documenting, and testing React component libraries
Stars: ✭ 1,201 (-51.71%)
Mutual labels:  components, jsx
Lucid
A UI component library from AppNexus.
Stars: ✭ 171 (-93.12%)
Mutual labels:  components, jsx
Capivarajs
✌️ Um novo jeito de criar componentes híbridos.
Stars: ✭ 97 (-96.1%)
Mutual labels:  framework, components
React Workshop
⚒ 🚧 This is a workshop for learning how to build React Applications
Stars: ✭ 114 (-95.42%)
Mutual labels:  components, jsx
Element
Programmatic UI for macOS
Stars: ✭ 855 (-65.62%)
Mutual labels:  framework, components
Asynquence
Asynchronous flow control (promises, generators, observables, CSP, etc)
Stars: ✭ 1,737 (-30.16%)
Mutual labels:  promises, generators
X0
Document & develop React components without breaking a sweat
Stars: ✭ 1,706 (-31.4%)
Mutual labels:  components, jsx
Antmove
小程序转换器,基于支付宝/微信小程序, 轻松地转换成其它平台的小程序。
Stars: ✭ 1,078 (-56.65%)
Mutual labels:  framework, components
Cmui
Lightweight UI solution for mobile web.
Stars: ✭ 182 (-92.68%)
Mutual labels:  framework, components
Preact
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Stars: ✭ 30,527 (+1127.46%)
Mutual labels:  components, jsx
Aleph.js
The Full-stack Framework in Deno.
Stars: ✭ 3,448 (+38.64%)
Mutual labels:  framework, components
Webmiddle
Node.js framework for modular web scraping and data extraction
Stars: ✭ 13 (-99.48%)
Mutual labels:  framework, jsx
Reactinterface
This is the repository for my course, Building a Web Interface with React.js on LinkedIn Learning and Lynda.com.
Stars: ✭ 113 (-95.46%)
Mutual labels:  framework, jsx
Catberry
Catberry is an isomorphic framework for building universal front-end apps using components, Flux architecture and progressive rendering.
Stars: ✭ 793 (-68.11%)
Mutual labels:  framework, components
Fprime
F' - A flight software and embedded systems framework
Stars: ✭ 8,642 (+247.49%)
Mutual labels:  framework, components
Redux React Starter
DEPRECATED use the new https://github.com/didierfranc/react-webpack-4
Stars: ✭ 137 (-94.49%)
Mutual labels:  components, jsx
React Scanner
Extract React components and props usage from code.
Stars: ✭ 176 (-92.92%)
Mutual labels:  components, jsx

Crank.js

Write JSX-driven components with functions, promises and generators.

Documentation is available at crank.js.org. Crank.js is in a beta phase, and some APIs may change. To read more about the motivations for this library, you can read the introductory blog post.

Features

Declarative

Crank uses the same JSX syntax and diffing algorithm popularized by React, allowing you to write HTML-like code directly in JavaScript.

Just Functions

All components in Crank are just functions or generator functions. No classes, hooks, proxies or template languages are needed.

Promise-friendly

Crank provides first-class support for promises. You can define components as async functions and race renderings to display fallback UIs.

Lightweight

Crank has no dependencies, and its core is a single file. It currently measures at 5KB minified and gzipped.

Performant

According to benchmarks, Crank beats React in terms of speed and memory usage, and is currently comparable to Preact or Vue.

Extensible

The core renderer can be extended to target alternative environments such as WebGL libraries, terminals, smartphones or smart TVs.

Installation

Crank is available on NPM in the ESModule and CommonJS formats.

$ npm install @b9g/crank
/** @jsx createElement */
import {createElement} from "@b9g/crank";
import {renderer} from "@b9g/crank/dom";

renderer.render(<div id="hello">Hello world</div>, document.body);

If your environment does not support ESModules (you may see a message like SyntaxError: Unexpected token export), you can import the CommonJS versions of the library under the cjs directory.

/** @jsx createElement */
import {createElement} from "@b9g/crank/cjs";
import {renderer} from "@b9g/crank/cjs/dom";

renderer.render(<div id="hello">Hello world</div>, document.body);

Key Examples

A Simple Component

/** @jsx createElement */
import {createElement} from "@b9g/crank";
import {renderer} from "@b9g/crank/dom";

function Greeting({name = "World"}) {
  return (
    <div>Hello {name}</div>
  );
}

renderer.render(<Greeting />, document.body);

Try on CodeSandbox

A Stateful Component

/** @jsx createElement */
import {createElement} from "@b9g/crank";
import {renderer} from "@b9g/crank/dom";

function *Timer() {
  let seconds = 0;
  const interval = setInterval(() => {
    seconds++;
    this.refresh();
  }, 1000);
  try {
    while (true) {
      yield <div>Seconds: {seconds}</div>;
    }
  } finally {
    clearInterval(interval);
  }
}

renderer.render(<Timer />, document.body);

Try on CodeSandbox

An Async Component

/** @jsx createElement */
import {createElement} from "@b9g/crank";
import {renderer} from "@b9g/crank/dom";

async function QuoteOfTheDay() {
  const res = await fetch("https://favqs.com/api/qotd");
  const {quote} = await res.json();
  return (
    <p>{quote.body}” – <a href={quote.url}>{quote.author}</a>
    </p>
  );
}

renderer.render(<QuoteOfTheDay />, document.body);

Try on CodeSandbox

A Loading Component

/** @jsx createElement */
import {createElement, Fragment} from "@b9g/crank";
import {renderer} from "@b9g/crank/dom";

async function LoadingIndicator() {
  await new Promise(resolve => setTimeout(resolve, 1000));
  return <div>Fetching a good boy...</div>;
}

async function RandomDog({throttle = false}) {
  const res = await fetch("https://dog.ceo/api/breeds/image/random");
  const data = await res.json();
  if (throttle) {
    await new Promise(resolve => setTimeout(resolve, 2000));
  }

  return (
    <a href={data.message}>
      <img src={data.message} alt="A Random Dog" width="300" />
    </a>
  );
}

async function *RandomDogLoader({throttle}) {
  for await ({throttle} of this) {
    yield <LoadingIndicator />;
    yield <RandomDog throttle={throttle} />;
  }
}

function *RandomDogApp() {
  let throttle = false;
  this.addEventListener("click", (ev) => {
    if (ev.target.tagName === "BUTTON") {
      throttle = !throttle;
      this.refresh();
    }
  });

  while (true) {
    yield (
      <Fragment>
        <div>
          <button>Show me another dog.</button>
        </div>
        <RandomDogLoader throttle={throttle} />
      </Fragment>
    );
  }
}

renderer.render(<RandomDogApp />, document.body);

Try on CodeSandbox

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].