Skip to content

Commit

Permalink
change _out property name
Browse files Browse the repository at this point in the history
  • Loading branch information
bySabi committed Mar 5, 2019
1 parent 0101e65 commit 4d28f88
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions example/pages/counters10x40blocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { createHookWithClass, Hookleton } from 'hookleton';

class Hookleton2 extends Hookleton {
useHost() {
useLayoutEffect(this._notify2.bind(this), [this._o[0]]);
return this._o;
useLayoutEffect(this._notify2.bind(this), [this._out[0]]);
return this._out;
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hookleton",
"version": "0.2.0",
"version": "0.2.1",
"description": "globalize your React Hooks without fear using the Hookleton Pattern",
"main": "lib/index.js",
"react-native": "lib/index.js",
Expand Down
20 changes: 10 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function createHook(useHook, ...initialArgs) {
export function createHookWithClass(HookletonClass, useHook, ...initialArgs) {
const hookleton = new HookletonClass(useHook, initialArgs);
const use = hookleton.use.bind(hookleton);
use.get = () => hookleton._o; // inject a 'get' for use it standalone
use.get = () => hookleton._out; // inject a 'get' for use it standalone
return use;
}

Expand All @@ -17,7 +17,7 @@ export class Hookleton {
this._a = initialArgs; // a const value. Don't mutate it
this._up = new Map(); // non-Host updaters container
this._h = false; // the have 'Host' flag
/* this._o is "The source of Truth", create on _init */
/* this._out is "The source of Truth", create on _init */
}

use(...initialArgs) {
Expand All @@ -32,11 +32,11 @@ export class Hookleton {
// This is the hookleton Host
if (refUse.current) {
// The call to provided `useHook`
this._o = this._hook(...this._arg); // return "The source of truth"
this._out = this._hook(...this._arg); // return "The source of truth"

// Checked on 'first' render only
useMemo(() => {
if (!Array.isArray(this._o)) {
if (!Array.isArray(this._out)) {
throw new Error('[Hookleton] provided Hook must return array values');
}
}, []);
Expand All @@ -56,8 +56,8 @@ export class Hookleton {
// Use a custom function `_notify2` that ignore first render, defined on '_init'
useHost() {
// notify non-host on each `_o[0` update
useEffect(() => this._notify2(), [this._o[0]]);
return this._o;
useEffect(() => this._notify2(), [this._out[0]]);
return this._out;
}

useNonHost() {
Expand All @@ -71,7 +71,7 @@ export class Hookleton {
return () => this._up.delete(updater); // on unmount
}, []);

return this._o;
return this._out;
}

_init({ refUse, initialArgs }) {
Expand All @@ -80,7 +80,7 @@ export class Hookleton {
this._h = true;

// init "The source of truth"
this._o = [];
this._out = [];

// now current `use Hook` component is the hookleton 'Host'
refUse.current = true;
Expand All @@ -96,10 +96,10 @@ export class Hookleton {
}

_notify() {
// `out[0]` is passed to updater. This value is not use here,
// `_out[0]` is passed to updater. This value is not use here,
// but could be useful for libs that extends Hookleton
// by CONVENTION `out[0]` it is assumed that is the state
this._up.forEach(updater => updater(this._o[0]));
this._up.forEach(updater => updater(this._out[0]));
}
}

Expand Down

0 comments on commit 4d28f88

Please sign in to comment.