Skip to content

Commit a118921

Browse files
committed
bump 0.4.0 go raw
1 parent f1e83cd commit a118921

30 files changed

+487
-1054
lines changed

README.md

+23-49
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Does _Hookleton_ make your life a little more easy? Consider <a href="https://ww
2929
- Low Memory Consumption and CPU Usage
3030
- Very fast, as fast as the React Hook _runtime_
3131
- Works in any environment that supports React Hook: _React Native_, _React Server-Side Rendering ([next.js](https://github.com/zeit/next.js/))_, _[Proto Native](https://github.com/kusti8/proton-native)_, ...
32-
- Extensible by advanced users
32+
- Extensible
3333
- Very low cognitive load
3434

3535
## Install
@@ -45,23 +45,8 @@ The Hookleton package exposes `createHook` function that does all.
4545

4646
- `useHook` is the user provide Hook
4747
- `initial` any params that _useHook_ will accept
48-
- `useHookleton` returned Hookleton
49-
50-
### a single convention
51-
52-
By **convention** Hookleton inspect for changes in element **1** of _array_ returned by _useHook_ before notify(_force render_) to users components of the hookleton.
53-
Make sure you update that value, `hook Output[0]`, if you want the changes to be notified.
54-
55-
An example, in case it has not been clear:
56-
57-
```javascript
58-
const useExample = createHook(() => {
59-
const [, setState] = useState(0);
60-
return ['any value', setState];
61-
});
62-
```
63-
64-
If you do something like this, when `setState` update state the hookleton **host** will be rendered but **Hookleton** will not see any change cause element **1** is a constant value, `any value`, hence the rest of users component will not be rendered.
48+
- `useHookleton` returned Hookleton. Called by *non-host* components
49+
- `useHookleton.use` returned Hookleton. Called by **the host** component
6550

6651
## usage Example
6752

@@ -88,11 +73,13 @@ const Decrement = () => {
8873
return <button onClick={decrement}>-</button>;
8974
};
9075

76+
// The host component
9177
const Value = () => {
92-
const [count] = useCounter(0);
78+
const [count] = useCounter.use(0);
9379
return <span>{count}</span>;
9480
};
9581

82+
// Value componet must be at the top
9683
export default () => (
9784
<div>
9885
<Value />
@@ -102,20 +89,20 @@ export default () => (
10289
);
10390
```
10491

105-
The `Value` component is the **host** of `useCounter` hookleton for being the first component of the hierarchy that _use_ it.
106-
Remember that `useCounter` is **composing** a `useState` which is where all the logic happens. It could have been any Hook that return an **Array**
92+
The `Value` component is the **host** of `useCounter` hookleton for being the first component of the hierarchy that call `useCounter.use`.
93+
Remember that `useCounter` is **composing** a `useState` which is where all the logic happens.
94+
95+
## a single convention
96+
Only one component, the `host`, can call created *hookleton* `use` hook and this component must be at the top of components of the hierarchy.
97+
10798

10899
## more Examples
109100

110101
Examples [page](https://bysabi.github.io/hookleton/) include:
111102

112103
- _Todo App_ [page](https://bysabi.github.io/hookleton/todo/) | [source](./example/pages/todo.js)
113-
- a _Mouse_ event listener that notify `{x,y}` position to 600 components in Real Time [page](https://bysabi.github.io/hookleton/mouse/) | [source](./example/pages/mouse.js)
104+
- a _Mouse_ event listener that notify `{x,y}` position to 1200 components in Real Time [page](https://bysabi.github.io/hookleton/mouse/) | [source](./example/pages/mouse.js)
114105
- basic _Counter_ showed above [page](https://bysabi.github.io/hookleton/counter/) | [source](./example/pages/counter.js)
115-
- 5 counters in 25 components. Include a basic `global store` [page](https://bysabi.github.io/hookleton/counters5x5/) | [source](./example/pages/counters5x5.js)
116-
- 5 counters in 400 components. Default non-blocking renderer [page](https://bysabi.github.io/hookleton/counters10x40/) | [source](./example/pages/counters10x40.js)
117-
- 5 counters in 400 components. With a custom blocking renderer [page](https://bysabi.github.io/hookleton/counters10x40blocking/) | [source](./example/pages/counters10x40blocking.js)
118-
- 10 counters in multiple nested context [page](https://bysabi.github.io/hookleton/counterNested/) | [source](./example/pages/counterNested.js)
119106
- showing Fetched 10 random users data in 16 components [page](https://bysabi.github.io/hookleton/fetch/) | [source](./example/pages/fetch.js)
120107

121108
How would it be with React Context vs Hookletons?
@@ -129,10 +116,9 @@ How would it be with React Context vs Hookletons?
129116

130117
The idea is very simple. The first time that a user component of the Hook is instantiated the hookleton is created and the result of the call to `user Hook` will be _linked_ to the `host` of the hookleton. The `user Hook` is the one you want to _globalize_.
131118
The result to the calls to the hookleton in the `host` component will become `The source of truth`. The rest of user components will receive a reference to _The source of truth_ on each **re-render**.
132-
As we said the `host` of the hookleton is the first component instance that _use_ it or _call_ it. This is important for two reasons:
119+
As we said the `host` of the hookleton is the first component instance that call `.use` hook. This is important because:
133120

134-
- First, initial state of the Hook only can be defined in the `host` or in the creation moment with `createHook`. Any _initial_ value from the rest of components will be ignored.
135-
- Second, when the host component is unmounted `non-host` will retain the state but you can not update it until a new component that will be designated `Host` is mounted
121+
- Initial state of the Hook only can be defined in the `host` or in the creation moment with `createHook`. Any _initial_ value from the rest of components will be ignored.
136122

137123
This is all that you need about _Hookletons_ before start to use it
138124

@@ -146,7 +132,7 @@ A cloudy day googling I was looking for the simplest possible alternative to _Re
146132

147133
This does not mean that they are badly constructed, just that they were not built on top of React Hook, they are prior to it or do not benefit at all of the **"Hook engine"**
148134

149-
Hookleton solves it elegantly. Actually _Hookleton_ does not know anything about the `useHook` that want to be global, it only matters that the hook returns an _array_ of any size, its runtime `interface`. This means that its utility is to share the _interface_ of the hook not only its state.
135+
Hookleton solves it elegantly. Actually _Hookleton_ does not know anything about the `useHook` that want to be global. This means that its utility is to share the _interface_ of the hook not only its state.
150136

151137
### When and Where use it
152138

@@ -160,19 +146,18 @@ Hookletons can be used in all kinds of projects, both large and small. Remember
160146

161147
## Pitfalls
162148

163-
1. If element **1** of the returned _array_ does not change, the users of the hookleton will not be notified
164-
2. There are two ways to set the initial value of the hookleton. When created with `createHook` and when it is called from the host component.
149+
1. There are two ways to set the initial value of the hookleton. When created with `createHook` and when it is called from the host component.
165150
- The value passed in `createHook` creation has priority
166-
- If it is `undefined` in _createHook_, the value set in the `host` component will be used. There is only one _host_ component, **the first one**
167-
3. `initial` values passed to **non-host** components will be **ignored**
168-
4. If the host component is **unmounted**, the calls to state `setter` will fail. To ensure that this does not happen, you can create a component that acts as the host of the hookleton or several of them at the top of the component hierarchy, Ex:
151+
- If it is `undefined` in _createHook_, the value set in the `host` component will be used. There is only one _host_ component.
152+
2. `initial` values passed to **non-host** components will be **ignored**
153+
3. If the host component is **unmounted**, the calls to state `setter` will fail. To ensure that this does not happen, you can create a component that acts as the host of the hookleton or several of them at the top of the component hierarchy, Ex:
169154

170155
```javascript
171156

172157
const Hookletons = () => {
173-
useExample1(0);
174-
useExample2('one');
175-
useExample3({ three: 3 });
158+
useExample1.use(0);
159+
useExample2.use('one');
160+
useExample3.use({ three: 3 });
176161
return null
177162
}
178163

@@ -192,17 +177,6 @@ If you compare it with other non-Hook based solutions, I do not know that it's t
192177

193178
You can see how the _rerender_ behave in the above provide examples: _Mouse_, _Counters_, and _Fetch data_
194179

195-
## advanced users API
196-
197-
Hookleton is implemented in an class with lifecycle methods that can be extended or replaced.
198-
199-
`import { Hookleton, createHookWithClass } from 'hookleton'`
200-
201-
- `Hookleton` it is the class that implements everything
202-
- `createHookWithClass` is a function for instantiate derived `Hookleton` classes and do some setup.
203-
204-
**\*createHook** is a _createHookWithClass_ function
205-
206180
## Credits
207181

208182
### author

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ['@babel/env', '@babel/preset-react'],
2+
presets: ['@babel/env'],
33
};

doc/ContextVsHookletons.md

Whitespace-only changes.

doc/Introduccing_Hookleton.md

-196
This file was deleted.

0 commit comments

Comments
 (0)