solid-js 1.2.0-beta.0 → 1.2.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/h/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # Solid HyperScript
2
+
3
+ This sub module provides a HyperScript method for Solid. This is useful to use Solid in non-compiled environments or in some environments where you can only use a standard JSX transform. This method can be used as the JSX factory function.
4
+
5
+ HyperScript function takes a few forms. The 2nd props argument is optional. Children may be passed as either an array to the 2nd/3rd argument or as every argument past the 2nd.
6
+
7
+ ```js
8
+ // create an element with a title attribute
9
+ h("button", { title: "My button" }, "Click Me")
10
+
11
+ // create a component with a title prop
12
+ h(Button, { title: "My button" }, "Click Me")
13
+
14
+ // create an element with many children
15
+ h("div", { title: "My button" }, h("span", "1"), h("span", "2"), h("span", "3"))
16
+ ```
17
+
18
+ This is the least efficient way to use Solid as it requires a slightly larger runtime that isn't treeshakebable, and cannot leverage anything in the way of analysis, so it requires manual wrapping of expressions and has a few other caveats (see below).
19
+
20
+ ## Example
21
+
22
+ ```js
23
+ import { render } from "solid-js/web";
24
+ import h from "solid-js/h";
25
+ import { createSignal } from "solid-js";
26
+
27
+ function Button(props) {
28
+ return h("button.btn-primary", props)
29
+ }
30
+
31
+ function Counter() {
32
+ const [count, setCount] = createSignal(0);
33
+ const increment = (e) => setCount(c => c + 1);
34
+
35
+ return h(Button, { type: "button", onClick: increment }, count);
36
+ }
37
+
38
+ render(Counter, document.getElementById("app"));
39
+ ```
40
+
41
+ ## Differences from JSX
42
+
43
+ There are a few differences from Solid's JSX that are important to note. And also apply when attempting use any transformation that would compile to HyperScript.
44
+
45
+ 1. Reactive expression must be manually wrapped in functions to be reactive.
46
+
47
+ ```js
48
+ // jsx
49
+ <div id={props.id}>{firstName() + lastName()}</div>
50
+
51
+ // hyperscript
52
+ h("div", { id: () => props.id }, () => firstName() + lastName())
53
+ ```
54
+
55
+ 2. Merging spreads requires using the merge props helper to keep reactivity
56
+
57
+ ```js
58
+ // jsx
59
+ <div class={selectedClass()} {...props} />
60
+
61
+ // hyperscript
62
+ import { mergeProps } from "solid-js"
63
+
64
+ h("div", mergeProps({ class: selectedClass }, props))
65
+ ```
66
+
67
+ 3. Events on components require explicit event in the arguments
68
+
69
+ Solid's HyperScript automatically wraps functions passed to props of components with no arguments in getters so you need to provide one to prevent this. The same applies to render props like in the `<For>` component.
70
+
71
+ ```js
72
+ // good
73
+ h(Button, { onClick: (e) => console.log("Hi")});
74
+
75
+ // bad
76
+ h(Button, { onClick: () => console.log("Hi")})
77
+ ```
78
+
79
+ 4. All refs are callback form
80
+
81
+ We can't do the compiled assigment trick so only the callback form is supported.
82
+
83
+ ```js
84
+ let myEl;
85
+
86
+ h(div, { ref: (el) => myEl = el });
87
+ ```
88
+
89
+ 5. There is a shorthand for static id and classes
90
+
91
+ ```js
92
+ h("div#some-id.my-class")
93
+ ```
94
+
95
+ 6. Fragments are just arrays
96
+
97
+ ```js
98
+ [h("span", "1"), h("span", "2")]
99
+ ```
package/html/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # Solid Tagged Template Literals
2
+
3
+ This sub module provides a Tagged Template Literal `html` method for Solid. This is useful to use Solid in non-compiled environments. This method can be used as replacement for JSX.
4
+
5
+ `html` uses `${}` to escape into JavaScript expressions. Components are closed with `<//>`
6
+
7
+ ```js
8
+ // create an element with a title attribute
9
+ html`<button title="My button">Click Me</button>`
10
+
11
+ // create a component with a title prop
12
+ html`<${Button} title="My button">Click me<//>`
13
+
14
+ // create an element with dynamic attribute and spread
15
+ html`<div title=${() => selectedClass()} ...${props} />`
16
+ ```
17
+
18
+ Using `html` is slightly less efficient than JSX(but more than HyperScript), requires a larger runtime that isn't treeshakebable, and cannot leverage expression analysis, so it requires manual wrapping of expressions and has a few other caveats (see below).
19
+
20
+ ## Example
21
+
22
+ ```js
23
+ import { render } from "solid-js/web";
24
+ import html from "solid-js/html";
25
+ import { createSignal } from "solid-js";
26
+
27
+ function Button(props) {
28
+ return html`<button class="btn-primary" ...${props} />`;
29
+ }
30
+
31
+ function Counter() {
32
+ const [count, setCount] = createSignal(0);
33
+ const increment = (e) => setCount((c) => c + 1);
34
+
35
+ return html`<${Button} type="button" onClick=${increment}>${count}<//>`;
36
+ }
37
+
38
+ render(Counter, document.getElementById("app"));
39
+ ```
40
+
41
+ ## Differences from JSX
42
+
43
+ There are a few differences from Solid's JSX that are important to note.
44
+
45
+ 1. Reactive expression must be manually wrapped in functions to be reactive.
46
+
47
+ ```js
48
+ // jsx
49
+ <div id={props.id}>{firstName() + lastName()}</div>
50
+
51
+ // hyperscript
52
+ html`<div id=${() => props.id}>${() => firstName() + lastName()}</div>`
53
+ ```
54
+
55
+ 2. Events on components require explicit event in the arguments
56
+
57
+ Solid's Tagged Template Literals automatically wraps functions passed to props of components with no arguments in getters so you need to provide one to prevent this. The same applies to render props like in the `<For>` component.
58
+
59
+ ```js
60
+ // good
61
+ html`<${Button} onClick=${(e) => console.log("Hi")} />`;
62
+
63
+ // bad
64
+ html`<${Button} onClick=${() => console.log("Hi")} />`;
65
+ ```
66
+
67
+ 4. All refs are callback form
68
+
69
+ We can't do the compiled assigment trick so only the callback form is supported.
70
+
71
+ ```js
72
+ let myEl;
73
+ html`<div ref=${(el) => myEl = el} />`;
74
+ ```
75
+
76
+ 5. There can be multiple top level elements
77
+
78
+ No need for fragments just:
79
+ ```js
80
+ html`
81
+ <div>1</div>
82
+ <div>2</div>
83
+ `
84
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solid-js",
3
3
  "description": "A declarative JavaScript library for building user interfaces.",
4
- "version": "1.2.0-beta.0",
4
+ "version": "1.2.0",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/solidjs/solid#readme",
@@ -132,5 +132,5 @@
132
132
  "compiler",
133
133
  "performance"
134
134
  ],
135
- "gitHead": "ec5bfa3adc09c0efd9210be6ff5096ec18c06d02"
135
+ "gitHead": "e6bbfa693db53cffd3372ee8bf1c61e3f1d47064"
136
136
  }
@@ -0,0 +1,23 @@
1
+ # Solid Store
2
+
3
+ This submodules contains the means for handling deeps nested reactivity. It provides 2 main primitives `createStore` and `createMutable` which leverage proxies to create dynamic nested reactive structures.
4
+
5
+ This also contains helper methods `produce` and `reconcile` which augment the behavior of the store setter method to allow for localized mutationa and data diffing.
6
+
7
+ For full documentation, check out the [website](https://www.solidjs.com/docs/latest/api).
8
+
9
+ ## Example
10
+
11
+ ```js
12
+ import { createStore } from "solid-js/store";
13
+
14
+ const [store, setStore] = createStore({
15
+ user: {
16
+ firstName: "John",
17
+ lastName: "Smith"
18
+ }
19
+ });
20
+
21
+ // update store.user.firstName
22
+ setStore("user", "firstName", "Will");
23
+ ```
package/types/jsx.d.ts CHANGED
@@ -11,7 +11,7 @@ export namespace JSX {
11
11
  | Node
12
12
  | ArrayElement
13
13
  | FunctionElement
14
- | string
14
+ | (string & {})
15
15
  | number
16
16
  | boolean
17
17
  | null
@@ -0,0 +1,102 @@
1
+ # Solid Universal
2
+
3
+ This contains the means to create the runtime for a custom renderer for Solid. This can enable using Solid to render to different platforms like native mobile and desktop, canvas or WebGL, or even the terminal. It relies on custom compilation from `babel-preset-solid` and exporting the result of `createRenderer` at a referenceable location.
4
+
5
+ ## Example
6
+
7
+ To use a custom renderer available in the (fictional) `solid-custom-dom` package you'd configure your babelrc as:
8
+ ```json
9
+ {
10
+ "presets": [
11
+ [
12
+ "babel-preset-solid",
13
+ {
14
+ "moduleName": "solid-custom-dom",
15
+ "generate": "universal"
16
+ }
17
+ ]
18
+ ]
19
+ }
20
+ ```
21
+
22
+ To create a custom renderer you must implement certain methods and export (as named exports) the results. You may also want to forward `solid-js` control flow to allow them to be auto imported as well.
23
+
24
+ ```js
25
+ // example custom dom renderer
26
+ import { createRenderer } from "solid-js/universal";
27
+
28
+ const PROPERTIES = new Set(["className", "textContent"]);
29
+
30
+ export const {
31
+ render,
32
+ effect,
33
+ memo,
34
+ createComponent,
35
+ createElement,
36
+ createTextNode,
37
+ insertNode,
38
+ insert,
39
+ spread,
40
+ setProp,
41
+ mergeProps
42
+ } = createRenderer({
43
+ createElement(string) {
44
+ return document.createElement(string);
45
+ },
46
+ createTextNode(value) {
47
+ return document.createTextNode(value);
48
+ },
49
+ replaceText(textNode, value) {
50
+ textNode.data = value;
51
+ },
52
+ setProperty(node, name, value) {
53
+ if (name === "style") Object.assign(node.style, value);
54
+ else if (name.startsWith("on")) node[name.toLowerCase()] = value;
55
+ else if (PROPERTIES.has(name)) node[name] = value;
56
+ else node.setAttribute(name, value);
57
+ },
58
+ insertNode(parent, node, anchor) {
59
+ parent.insertBefore(node, anchor);
60
+ },
61
+ isTextNode(node) {
62
+ return node.type === 3;
63
+ },
64
+ removeNode(parent, node) {
65
+ parent.removeChild(node);
66
+ },
67
+ getParentNode(node) {
68
+ return node.parentNode;
69
+ },
70
+ getFirstChild(node) {
71
+ return node.firstChild;
72
+ },
73
+ getNextSibling(node) {
74
+ return node.nextSibling;
75
+ }
76
+ });
77
+
78
+ // Forward Solid control flow
79
+ export {
80
+ For,
81
+ Show,
82
+ Suspense,
83
+ SuspenseList,
84
+ Switch,
85
+ Match,
86
+ Index,
87
+ ErrorBoundary
88
+ } from "solid-js";
89
+ ```
90
+
91
+ Then to consume:
92
+ ```js
93
+ import { render } from "solid-custom-dom";
94
+
95
+ function App() {
96
+ // the skies the limits
97
+ }
98
+
99
+ render(() => <App />, mountNode)
100
+ ```
101
+
102
+ > Note: For TypeScript support of non-standard JSX you will need to provide your own types at a jsx-runtime entry on your package so that it can be set as the `jsxImportSource`. If mixing and matching different JSX implementations you will need use the per file pragmas.
package/web/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Solid Web
2
+
3
+ This submodule contains the web specific APIs for Solid that are mostly internal methods imported during compilation. It has all the code to render for the web on the server and the browser.
4
+
5
+ In addition this modules provides the primary entry point methods `render`, `hydrate`, `renderToString`, `renderToStringAsync`, `pipeToNodeWritable`, and `pipeToWritable`. As well as a few web specific control flow components `<Portal>` and `<Dynamic>`.
6
+
7
+ Refer to the [website](https://www.solidjs.com/docs/latest/api) for documentation.