@b9g/crank 0.4.4 → 0.5.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -50
- package/crank.cjs +27 -6
- package/crank.cjs.map +1 -1
- package/crank.d.ts +3 -3
- package/crank.js +27 -7
- package/crank.js.map +1 -1
- package/index.cjs +3 -1
- package/index.cjs.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/package.json +25 -17
- package/umd.js +27 -6
- package/umd.js.map +1 -1
- package/xm.cjs +431 -0
- package/xm.cjs.map +1 -0
- package/xm.d.ts +2 -0
- package/xm.js +428 -0
- package/xm.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,55 +1,25 @@
|
|
|
1
1
|
# Crank.js
|
|
2
|
-
|
|
2
|
+
### The most “Just JavaScript” web framework.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Crank.js is a framework where components are defined with *Plain Old JavaScript Functions*. But not just regular functions! Components can also be defined with async functions for working with promises, and generator functions for working with local state.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
### Declarative
|
|
8
|
-
Crank uses the same JSX syntax and diffing algorithm popularized by React, allowing you to write HTML-like code directly in JavaScript.
|
|
6
|
+
Its API aims to be minimal and transparent. By relying on standard JavaScript control flow operators and data structures, and by making the process of rendering explicit, Crank.js helps developers write durable, bug-free applications with the latest and greatest libraries and APIs.
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
All components in Crank are just functions or generator functions. No classes, hooks, proxies or template languages are needed.
|
|
8
|
+
Rather than forcing developers to work with increasingly convoluted reactive solutions and bespoke templating languages, Crank.js uses the platform. It is a dedication to the web, to the promise of an accessible and inclusive medium for self-expression and commerce, built on the thesis that simpler code is how we’ll push the frontier.
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
Crank provides first-class support for promises. You can define components as async functions and race renderings to display fallback UIs.
|
|
10
|
+
## Get Started
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
Crank has no dependencies, and its core is a single file. It currently measures at [5KB minified and gzipped](https://bundlephobia.com/result?p=@b9g/crank).
|
|
18
|
-
|
|
19
|
-
### Performant
|
|
20
|
-
[According to benchmarks](https://github.com/krausest/js-framework-benchmark), Crank beats React in terms of speed and memory usage, and is currently comparable to Preact or Vue.
|
|
21
|
-
|
|
22
|
-
### Extensible
|
|
23
|
-
The core renderer can be extended to target alternative environments such as WebGL libraries, terminals, smartphones or smart TVs.
|
|
24
|
-
|
|
25
|
-
## Installation
|
|
26
|
-
Crank is available on [NPM](https://npmjs.org/@b9g/crank) in the ESModule and CommonJS formats.
|
|
12
|
+
The documentation for Crank.js is available at [crank.js.org](https://crank.js.org). Crank.js is published on NPM under the `@b9g` organization (short for “b*ikeshavin*g”).
|
|
27
13
|
|
|
28
14
|
```shell
|
|
29
15
|
$ npm install @b9g/crank
|
|
30
16
|
```
|
|
31
17
|
|
|
32
|
-
|
|
33
|
-
/** @jsx createElement */
|
|
34
|
-
import {createElement} from "@b9g/crank";
|
|
35
|
-
import {renderer} from "@b9g/crank/dom";
|
|
36
|
-
|
|
37
|
-
renderer.render(<div id="hello">Hello world</div>, document.body);
|
|
38
|
-
```
|
|
18
|
+
### Key Examples
|
|
39
19
|
|
|
40
|
-
|
|
20
|
+
#### A Simple Component
|
|
41
21
|
|
|
42
|
-
```jsx
|
|
43
|
-
/** @jsx createElement */
|
|
44
|
-
import {createElement} from "@b9g/crank/cjs";
|
|
45
|
-
import {renderer} from "@b9g/crank/cjs/dom";
|
|
46
|
-
|
|
47
|
-
renderer.render(<div id="hello">Hello world</div>, document.body);
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Key Examples
|
|
51
|
-
### A Simple Component
|
|
52
|
-
```jsx
|
|
22
|
+
```jsx live
|
|
53
23
|
/** @jsx createElement */
|
|
54
24
|
import {createElement} from "@b9g/crank";
|
|
55
25
|
import {renderer} from "@b9g/crank/dom";
|
|
@@ -63,10 +33,9 @@ function Greeting({name = "World"}) {
|
|
|
63
33
|
renderer.render(<Greeting />, document.body);
|
|
64
34
|
```
|
|
65
35
|
|
|
66
|
-
|
|
36
|
+
#### A Stateful Component
|
|
67
37
|
|
|
68
|
-
|
|
69
|
-
```jsx
|
|
38
|
+
```jsx live
|
|
70
39
|
/** @jsx createElement */
|
|
71
40
|
import {createElement} from "@b9g/crank";
|
|
72
41
|
import {renderer} from "@b9g/crank/dom";
|
|
@@ -89,10 +58,9 @@ function *Timer() {
|
|
|
89
58
|
renderer.render(<Timer />, document.body);
|
|
90
59
|
```
|
|
91
60
|
|
|
92
|
-
|
|
61
|
+
#### An Async Component
|
|
93
62
|
|
|
94
|
-
|
|
95
|
-
```jsx
|
|
63
|
+
```jsx live
|
|
96
64
|
/** @jsx createElement */
|
|
97
65
|
import {createElement} from "@b9g/crank";
|
|
98
66
|
import {renderer} from "@b9g/crank/dom";
|
|
@@ -110,10 +78,9 @@ async function QuoteOfTheDay() {
|
|
|
110
78
|
renderer.render(<QuoteOfTheDay />, document.body);
|
|
111
79
|
```
|
|
112
80
|
|
|
113
|
-
[Try on CodeSandbox](https://codesandbox.io/s/an-async-crank-component-ru02q)
|
|
114
|
-
|
|
115
81
|
### A Loading Component
|
|
116
|
-
|
|
82
|
+
|
|
83
|
+
```jsx live
|
|
117
84
|
/** @jsx createElement */
|
|
118
85
|
import {createElement, Fragment} from "@b9g/crank";
|
|
119
86
|
import {renderer} from "@b9g/crank/dom";
|
|
@@ -167,5 +134,3 @@ function *RandomDogApp() {
|
|
|
167
134
|
|
|
168
135
|
renderer.render(<RandomDogApp />, document.body);
|
|
169
136
|
```
|
|
170
|
-
|
|
171
|
-
[Try on CodeSandbox](https://codesandbox.io/s/a-loading-crank-component-pci9d)
|
package/crank.cjs
CHANGED
|
@@ -108,6 +108,7 @@ class Element {
|
|
|
108
108
|
this.static_ = static_;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
+
// See Element interface
|
|
111
112
|
Element.prototype.$$typeof = ElementSymbol;
|
|
112
113
|
function isElement(value) {
|
|
113
114
|
return value != null && value.$$typeof === ElementSymbol;
|
|
@@ -130,6 +131,7 @@ function createElement(tag, props, ...children) {
|
|
|
130
131
|
switch (name) {
|
|
131
132
|
case "crank-key":
|
|
132
133
|
case "c-key":
|
|
134
|
+
case "$key":
|
|
133
135
|
// We have to make sure we don’t assign null to the key because we
|
|
134
136
|
// don’t check for null keys in the diffing functions.
|
|
135
137
|
if (props[name] != null) {
|
|
@@ -138,12 +140,14 @@ function createElement(tag, props, ...children) {
|
|
|
138
140
|
break;
|
|
139
141
|
case "crank-ref":
|
|
140
142
|
case "c-ref":
|
|
143
|
+
case "$ref":
|
|
141
144
|
if (typeof props[name] === "function") {
|
|
142
145
|
ref = props[name];
|
|
143
146
|
}
|
|
144
147
|
break;
|
|
145
148
|
case "crank-static":
|
|
146
149
|
case "c-static":
|
|
150
|
+
case "$static":
|
|
147
151
|
static_ = !!props[name];
|
|
148
152
|
break;
|
|
149
153
|
default:
|
|
@@ -157,11 +161,27 @@ function createElement(tag, props, ...children) {
|
|
|
157
161
|
else if (children.length === 1) {
|
|
158
162
|
props1.children = children[0];
|
|
159
163
|
}
|
|
164
|
+
// string aliases for the special tags
|
|
165
|
+
// TODO: Does this logic belong here, or in the Element constructor
|
|
166
|
+
switch (tag) {
|
|
167
|
+
case "$FRAGMENT":
|
|
168
|
+
tag = Fragment;
|
|
169
|
+
break;
|
|
170
|
+
case "$PORTAL":
|
|
171
|
+
tag = Portal;
|
|
172
|
+
break;
|
|
173
|
+
case "$COPY":
|
|
174
|
+
tag = Copy;
|
|
175
|
+
break;
|
|
176
|
+
case "$RAW":
|
|
177
|
+
tag = Raw;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
160
180
|
return new Element(tag, props1, key, ref, static_);
|
|
161
181
|
}
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
*/
|
|
182
|
+
/** A single-letter alias for createElement */
|
|
183
|
+
const c = createElement;
|
|
184
|
+
/** Clones a given element, shallowly copying the props object. */
|
|
165
185
|
function cloneElement(el) {
|
|
166
186
|
if (!isElement(el)) {
|
|
167
187
|
throw new TypeError("Cannot clone non-element");
|
|
@@ -735,9 +755,9 @@ const IsDone = 1 << 4;
|
|
|
735
755
|
*
|
|
736
756
|
* NOTE: This is mainly used to prevent some false positives in component
|
|
737
757
|
* yields or returns undefined warnings. The reason we’re using this versus
|
|
738
|
-
* IsUnmounted is a very troubling
|
|
739
|
-
*
|
|
740
|
-
*
|
|
758
|
+
* IsUnmounted is a very troubling test (cascades sync generator parent and
|
|
759
|
+
* sync generator child) where synchronous code causes a stack overflow error
|
|
760
|
+
* in a non-deterministic way. Deeply disturbing stuff.
|
|
741
761
|
*/
|
|
742
762
|
const IsErrored = 1 << 5;
|
|
743
763
|
/**
|
|
@@ -1645,6 +1665,7 @@ exports.Fragment = Fragment;
|
|
|
1645
1665
|
exports.Portal = Portal;
|
|
1646
1666
|
exports.Raw = Raw;
|
|
1647
1667
|
exports.Renderer = Renderer;
|
|
1668
|
+
exports.c = c;
|
|
1648
1669
|
exports.cloneElement = cloneElement;
|
|
1649
1670
|
exports.createElement = createElement;
|
|
1650
1671
|
exports["default"] = crank;
|