Skip to content

Commit 04a6748

Browse files
committed
Renamed 'extensions' to 'hooks' => 'js-element/ext' to 'js-elements/hooks' | API changes | etc.
1 parent 9e8d9b7 commit 04a6748

31 files changed

+972
-989
lines changed

.storybook/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module.exports = ({ config }) => {
1414
const alias = (config.resolve && config.resolve.alias) || {}
1515

1616
alias['js-elements$'] = path.resolve(__dirname, '../src/main/js-elements.ts')
17-
alias['js-elements/ext$'] = path.resolve(
17+
alias['js-elements/hooks$'] = path.resolve(
1818
__dirname,
19-
'../src/main/js-elements-ext.ts'
19+
'../src/main/js-elements-hooks.ts'
2020
)
2121

2222
config.resolve.alias = alias

README.md

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ and btw: It is currently not meant to ever be used in production.
1414
```jsx
1515
import { component, h, prop, render } from 'js-elements'
1616

17-
const SayHello = component('say-hello', {
17+
const SayHello = component('say-hello')({
1818
props: {
1919
salutation: prop.str.opt('Hello'),
2020
name: prop.str.opt('World')
2121
}
22-
}, (c, props) => {
22+
})((c, props) => {
2323
return () => (
2424
<div>
2525
{props.salutation}, {props.name}!
@@ -34,26 +34,30 @@ render(<SayHello salutation="Hi" name="Jane Doe" />, '#app')
3434

3535
```jsx
3636
import { component, h, prop, render } from 'js-elements'
37+
import { useEffect, useState, useStyles } from 'js-elements/hooks'
3738
import counterStyles from './counter.css'
3839

39-
const Counter = component('demo-counter', {
40+
const Counter = component('demo-counter')({
4041
props: {
4142
initialCount: prop.num.opt(0),
4243
label: prop.str.opt('Counter')
4344
}
44-
}, (c, props) => {
45-
let count = props.initialCount
46-
47-
const onClick = () => {
48-
++count
49-
c.refresh()
50-
}
51-
52-
c.addStyles(counterStyles)
53-
c.afterMount(() => console.log(`"${props.label}" has been mounted`))
54-
c.beforeUnmount(() => console.log(`Unmounting "${props.label}"`))
55-
56-
c.effect(
45+
})(c, props) => {
46+
const [state, setState] = useState(c, {
47+
count: props.initialCount
48+
})
49+
50+
const onClick = () => setState('count', it => it + 1)
51+
52+
useStyles(c, counterStyles)
53+
54+
useOnMount(c, () => {
55+
console.log(`"${props.label}" has been mounted`)
56+
57+
return () => console.log(`Unmounting "${props.label}"`)
58+
})
59+
60+
useEffect(c)(
5761
() => console.log(`Value of "${props.label}": ${count}`),
5862
() => [count]
5963
)
@@ -71,47 +75,16 @@ const Counter = component('demo-counter', {
7175
render(<Counter />, '#app')
7276
```
7377

74-
Unfortunatlely, if you are using the prettier code formatter, the
75-
above shown syntax will be reformatted in a way that you may not
76-
necessarily want.
77-
Therefore the following more prettier friendly alternative syntax
78-
is also allowed:
79-
80-
```jsx
81-
import { component, h, prop } from 'js-elements'
82-
83-
export default component('demo-counter', {
84-
props: {
85-
initialCount: prop.num.opt(0),
86-
label: prop.str.opt('Counter')
87-
}
88-
}).from((c, props) => {
89-
let count = props.initialCount
90-
91-
const onClick = () => {
92-
++count
93-
c.refresh()
94-
}
95-
96-
return () => (
97-
<div>
98-
<label>{props.label}: </label>
99-
<button onClick={onClick}>{count}</button>
100-
</div>
101-
)
102-
})
103-
```
104-
105-
_js-elements_ also supports so-called "extensions" which are
78+
_js-elements_ supports so-called "hooks" which are
10679
functions similar to React hooks (but without all the magic).
107-
All of those "extensions" can be written completely in userland
108-
(means there are no such things like "core extensions").
80+
All of those "hooks" can be written completely in userland
81+
(means there are no such things like "core hooks").
10982

11083
```jsx
11184
import { component, h } from 'js-elements'
112-
import { useTime } from 'js-elements/ext'
85+
import { useTime } from 'js-elements/hooks'
11386

114-
const Clock = component('demo-clock', (c) => {
87+
const Clock = component('demo-clock')((c) => {
11588
const getTime = useTime(c, 1000, () => new Date().toLocaleTimeString())
11689
return () => <div>Current time: {getTime()}</div>
11790
})

ext/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

ext/package.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

hooks/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('../dist/js-elements-hooks.cjs.production.js')
5+
} else {
6+
module.exports = require('../dist/js-elements-hooks.cjs.development.js')
7+
}

hooks/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "js-elements-hooks",
3+
"version": "0.0.1",
4+
"description": "",
5+
"main": "index.js",
6+
"module": "../dist/js-elements-hooks.esm.producion.js",
7+
"unpkg": "../dist/js-elements-hooks.umd.production.js",
8+
"jsdelivr": "../dist/js-elements-hooks.umd.production.js",
9+
"types": "../dist/types/js-elements-hooks.d.ts"
10+
}

0 commit comments

Comments
 (0)