vite-plugin-hyperapp 1.2.0 → 1.3.1

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.
Files changed (3) hide show
  1. package/README.md +49 -31
  2. package/index.js +2 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,7 +12,7 @@ Use vite as a dev-server and bundler for your hyperapp projects. Supports:
12
12
  To get up and running with Hyperapp and Vite in a few seconds, use [create-vite-hyperapp](https://github.com/zaceno/create-vite-hyperapp):
13
13
 
14
14
  ```sh
15
- > npm create vite-hyperapp
15
+ > npm create vite-hyperapp@latest
16
16
  ```
17
17
 
18
18
  > Use `npm create vite-hyperapp -- --help` for some command line options.
@@ -55,36 +55,6 @@ add this line in your `src/vite-env.d.ts`:
55
55
  /// <reference types="vite-plugin-hyperapp/jsx" />
56
56
  ```
57
57
 
58
- ## JSX/TSX
59
-
60
- Our JSX/TSX works the same as React/Preact, however, note that when you pass children to a component, like:
61
-
62
- ```jsx
63
- <MyComponent>
64
- <p>foo</p>
65
- <p>bar</p>
66
- </MyComponent>
67
- ```
68
-
69
- they will arrive as an array of virtual nodes in the _second_ argument to the component.
70
-
71
- ```jsx
72
- const MyComponent = (props, children) => {
73
- //children will be: [<p>foo</p>, <p>bar</p>]
74
- }
75
- ```
76
-
77
- It's ok to put this array of children among other children, because the jsx transform will flatten the child-list:
78
-
79
- ```jsx
80
- const MyComponent = (props, children) => (
81
- <div>
82
- <h1>Header</h1>
83
- {children} {/* <--- this is fine */}
84
- </div>
85
- )
86
- ```
87
-
88
58
  ## Hot-module-reloading (HMR)
89
59
 
90
60
  > The following is taken care of already, when you scaffold your app with `npm create vite-hyperapp`, but it is useful to be aware of
@@ -181,3 +151,51 @@ Then you _DON'T_ add your ssr outlet like this:
181
151
 
182
152
  And you make sure that the root-node of your view has `id="app"`.
183
153
 
154
+
155
+ ## Important Notes
156
+
157
+ ### Main view with TSX
158
+
159
+ TSX-expressions necessarily return the hyperapp type `MaybeVNode<State> | MaybeVNode<State>[]`. However, that is too loose for the `view` you pass to hyperapp's `app({...})` call. Therefore, you need to cast the return of your main view to `VNode<State>` (and of course make sure this is true, also).
160
+
161
+ ```ts
162
+ import {type VNode} from 'hyperapp'
163
+ ...
164
+
165
+ export const view = (state:State) => (
166
+ <main id="app">
167
+ ...
168
+ </main>
169
+ ) as VNode<State>
170
+ ```
171
+
172
+ ### JSX/TSX children
173
+
174
+ When you pass children to a component, like:
175
+
176
+ ```jsx
177
+ <MyComponent>
178
+ <p>foo</p>
179
+ <p>bar</p>
180
+ </MyComponent>
181
+ ```
182
+
183
+ they will arrive as an array of virtual nodes in the _second_ argument to the component.
184
+
185
+ ```jsx
186
+ const MyComponent = (props, children) => {
187
+ //children will be: [<p>foo</p>, <p>bar</p>]
188
+ }
189
+ ```
190
+
191
+ It's ok to put this array of children among other children, because the jsx transform will flatten the child-list:
192
+
193
+ ```jsx
194
+ const MyComponent = (props, children) => (
195
+ <div>
196
+ <h1>Header</h1>
197
+ {children} {/* <--- this is fine */}
198
+ </div>
199
+ )
200
+ ```
201
+
package/index.js CHANGED
@@ -32,10 +32,10 @@ export default function injectConsoleLog(options = {}) {
32
32
 
33
33
  config: () => ({
34
34
  esbuild: {
35
- jsxFactory: "jsxNode",
35
+ jsxFactory: "jsx",
36
36
  jsxFragment: "jsxFragment",
37
37
  jsxInject:
38
- "import {jsxNode, jsxFragment} from 'vite-plugin-hyperapp/jsx.js'",
38
+ "import {jsx, jsxFragment} from 'vite-plugin-hyperapp/jsx.js'",
39
39
  },
40
40
  }),
41
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-hyperapp",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "description": "Plugin and helpers for using Hyperapp with Vite",
6
6
  "main": "./index.js",