Comparing version 4.8.1 to 4.8.2
@@ -26,2 +26,8 @@ import { directive, render } from 'https://unpkg.com/lit-html@^1.0.0/lit-html.js'; | ||
class State { | ||
update; | ||
host; | ||
virtual; | ||
[hookSymbol]; | ||
[effectsSymbol]; | ||
[layoutEffectsSymbol]; | ||
constructor(update, host) { | ||
@@ -86,2 +92,7 @@ this.update = update; | ||
class BaseScheduler { | ||
renderer; | ||
host; | ||
state; | ||
[phaseSymbol]; | ||
_updateQueued; | ||
constructor(renderer, host) { | ||
@@ -135,2 +146,3 @@ this.renderer = renderer; | ||
class Scheduler extends BaseScheduler { | ||
frag; | ||
constructor(renderer, frag, host) { | ||
@@ -148,2 +160,6 @@ super(renderer, host || frag); | ||
class Element extends BaseElement { | ||
_scheduler; | ||
static get observedAttributes() { | ||
return renderer.observedAttributes || observedAttributes || []; | ||
} | ||
constructor() { | ||
@@ -159,5 +175,2 @@ super(); | ||
} | ||
static get observedAttributes() { | ||
return renderer.observedAttributes || observedAttributes || []; | ||
} | ||
connectedCallback() { | ||
@@ -192,3 +205,5 @@ this._scheduler.update(); | ||
value = newValue; | ||
this._scheduler.update(); | ||
if (this._scheduler) { | ||
this._scheduler.update(); | ||
} | ||
} | ||
@@ -237,2 +252,4 @@ }); | ||
class Hook { | ||
id; | ||
state; | ||
constructor(id, state) { | ||
@@ -259,2 +276,6 @@ this.id = id; | ||
return hook(class extends Hook { | ||
callback; | ||
lastValues; | ||
values; | ||
_teardown; | ||
constructor(id, state, ignored1, ignored2) { | ||
@@ -292,5 +313,15 @@ super(id, state); | ||
} | ||
/** | ||
* @function | ||
* @param {() => void} effect - callback function that runs each time dependencies change | ||
* @param {unknown[]} [dependencies] - list of dependencies to the effect | ||
* @return {void} | ||
*/ | ||
const useEffect = createEffect(setEffects); | ||
const useContext = hook(class extends Hook { | ||
Context; | ||
value; | ||
_ranEffect; | ||
_unsubscribe; | ||
constructor(id, state, _) { | ||
@@ -332,3 +363,3 @@ super(id, state); | ||
cancelable: true, | ||
composed: true, | ||
composed: true, // to pass ShadowDOM boundaries | ||
})); | ||
@@ -350,2 +381,4 @@ const { unsubscribe = null, value } = detail; | ||
Provider: class extends HTMLElement { | ||
listeners; | ||
_value; | ||
constructor() { | ||
@@ -392,2 +425,4 @@ super(); | ||
const useMemo = hook(class extends Hook { | ||
value; | ||
values; | ||
constructor(id, state, fn, values) { | ||
@@ -417,3 +452,10 @@ super(id, state); | ||
/** | ||
* @function | ||
* @template {*} T | ||
* @param {T} [initialState] - Optional initial state | ||
* @return {readonly [state: T, updaterFn: StateUpdater<T>]} stateTuple - Tuple of current state and state updater function | ||
*/ | ||
const useState = hook(class extends Hook { | ||
args; | ||
constructor(id, state, initialValue) { | ||
@@ -455,7 +497,11 @@ super(id, state); | ||
class HauntedControllerHost { | ||
count; | ||
kick; | ||
_controllers = []; | ||
_updatePending = true; | ||
_updateCompletePromise; | ||
_resolveUpdate; | ||
constructor(count, kick) { | ||
this.count = count; | ||
this.kick = kick; | ||
this._controllers = []; | ||
this._updatePending = true; | ||
this._updateCompletePromise = new Promise(res => { | ||
@@ -534,2 +580,4 @@ this._resolveUpdate = res; | ||
const useReducer = hook(class extends Hook { | ||
reducer; | ||
currentState; | ||
constructor(id, state, _, initialState, init) { | ||
@@ -565,2 +613,3 @@ super(id, state); | ||
class Scheduler extends BaseScheduler { | ||
args; | ||
constructor(renderer, part) { | ||
@@ -567,0 +616,0 @@ super(renderer, part); |
@@ -5,2 +5,3 @@ import { BaseScheduler } from './scheduler.js'; | ||
class Scheduler extends BaseScheduler { | ||
frag; | ||
constructor(renderer, frag, host) { | ||
@@ -18,2 +19,6 @@ super(renderer, host || frag); | ||
class Element extends BaseElement { | ||
_scheduler; | ||
static get observedAttributes() { | ||
return renderer.observedAttributes || observedAttributes || []; | ||
} | ||
constructor() { | ||
@@ -29,5 +34,2 @@ super(); | ||
} | ||
static get observedAttributes() { | ||
return renderer.observedAttributes || observedAttributes || []; | ||
} | ||
connectedCallback() { | ||
@@ -63,3 +65,5 @@ this._scheduler.update(); | ||
value = newValue; | ||
this._scheduler.update(); | ||
if (this._scheduler) { | ||
this._scheduler.update(); | ||
} | ||
} | ||
@@ -66,0 +70,0 @@ }); |
@@ -7,2 +7,4 @@ import { contextEvent } from './symbols.js'; | ||
Provider: class extends HTMLElement { | ||
listeners; | ||
_value; | ||
constructor() { | ||
@@ -9,0 +11,0 @@ super(); |
import { Hook, hook } from './hook.js'; | ||
function createEffect(setEffects) { | ||
return hook(class extends Hook { | ||
callback; | ||
lastValues; | ||
values; | ||
_teardown; | ||
constructor(id, state, ignored1, ignored2) { | ||
@@ -5,0 +9,0 @@ super(id, state); |
import { current, notify } from './interface.js'; | ||
import { hookSymbol } from './symbols.js'; | ||
class Hook { | ||
id; | ||
state; | ||
constructor(id, state) { | ||
@@ -5,0 +7,0 @@ this.id = id; |
@@ -25,2 +25,7 @@ import { State } from './state.js'; | ||
class BaseScheduler { | ||
renderer; | ||
host; | ||
state; | ||
[phaseSymbol]; | ||
_updateQueued; | ||
constructor(renderer, host) { | ||
@@ -27,0 +32,0 @@ this.renderer = renderer; |
import { setCurrent, clear } from './interface.js'; | ||
import { hookSymbol, effectsSymbol, layoutEffectsSymbol } from './symbols.js'; | ||
class State { | ||
update; | ||
host; | ||
virtual; | ||
[hookSymbol]; | ||
[effectsSymbol]; | ||
[layoutEffectsSymbol]; | ||
constructor(update, host) { | ||
@@ -5,0 +11,0 @@ this.update = update; |
@@ -5,2 +5,6 @@ import { hook, Hook } from './hook.js'; | ||
const useContext = hook(class extends Hook { | ||
Context; | ||
value; | ||
_ranEffect; | ||
_unsubscribe; | ||
constructor(id, state, _) { | ||
@@ -42,3 +46,3 @@ super(id, state); | ||
cancelable: true, | ||
composed: true, | ||
composed: true, // to pass ShadowDOM boundaries | ||
})); | ||
@@ -45,0 +49,0 @@ const { unsubscribe = null, value } = detail; |
@@ -14,7 +14,11 @@ /** | ||
class HauntedControllerHost { | ||
count; | ||
kick; | ||
_controllers = []; | ||
_updatePending = true; | ||
_updateCompletePromise; | ||
_resolveUpdate; | ||
constructor(count, kick) { | ||
this.count = count; | ||
this.kick = kick; | ||
this._controllers = []; | ||
this._updatePending = true; | ||
this._updateCompletePromise = new Promise(res => { | ||
@@ -21,0 +25,0 @@ this._resolveUpdate = res; |
import { State, Callable } from './state'; | ||
declare function setEffects(state: State, cb: Callable): void; | ||
/** | ||
* @function | ||
* @param {() => void} effect - callback function that runs each time dependencies change | ||
* @param {unknown[]} [dependencies] - list of dependencies to the effect | ||
* @return {void} | ||
*/ | ||
declare const useEffect: (callback: (this: State<unknown>) => void | VoidFunction, values?: unknown[] | undefined) => void; | ||
export { setEffects, useEffect }; |
@@ -6,3 +6,9 @@ import { effectsSymbol } from './symbols.js'; | ||
} | ||
/** | ||
* @function | ||
* @param {() => void} effect - callback function that runs each time dependencies change | ||
* @param {unknown[]} [dependencies] - list of dependencies to the effect | ||
* @return {void} | ||
*/ | ||
const useEffect = createEffect(setEffects); | ||
export { setEffects, useEffect }; |
import { hook, Hook } from './hook.js'; | ||
const useMemo = hook(class extends Hook { | ||
value; | ||
values; | ||
constructor(id, state, fn, values) { | ||
@@ -4,0 +6,0 @@ super(id, state); |
import { hook, Hook } from './hook.js'; | ||
const useReducer = hook(class extends Hook { | ||
reducer; | ||
currentState; | ||
constructor(id, state, _, initialState, init) { | ||
@@ -4,0 +6,0 @@ super(id, state); |
declare type NewState<T> = T | ((previousState?: T) => T); | ||
declare type StateUpdater<T> = (value: NewState<T>) => void; | ||
/** | ||
* @function | ||
* @template {*} T | ||
* @param {T} [initialState] - Optional initial state | ||
* @return {readonly [state: T, updaterFn: StateUpdater<T>]} stateTuple - Tuple of current state and state updater function | ||
*/ | ||
declare const useState: <T>(initialValue: T) => readonly [T extends (...args: any[]) => infer R ? R : T, StateUpdater<T extends (...args: any[]) => infer S ? S : T>]; | ||
export { useState }; |
import { hook, Hook } from './hook.js'; | ||
/** | ||
* @function | ||
* @template {*} T | ||
* @param {T} [initialState] - Optional initial state | ||
* @return {readonly [state: T, updaterFn: StateUpdater<T>]} stateTuple - Tuple of current state and state updater function | ||
*/ | ||
const useState = hook(class extends Hook { | ||
args; | ||
constructor(id, state, initialValue) { | ||
@@ -4,0 +11,0 @@ super(id, state); |
@@ -8,2 +8,3 @@ import { directive } from 'lit-html'; | ||
class Scheduler extends BaseScheduler { | ||
args; | ||
constructor(renderer, part) { | ||
@@ -10,0 +11,0 @@ super(renderer, part); |
{ | ||
"name": "haunted", | ||
"version": "4.8.1", | ||
"version": "4.8.2", | ||
"description": "Hooks for web components", | ||
@@ -8,7 +8,11 @@ "main": "lib/haunted.js", | ||
"type": "module", | ||
"customElements": "custom-elements.json", | ||
"scripts": { | ||
"build": "make", | ||
"analyze": "make && cem analyze", | ||
"preversion": "make", | ||
"server": "http-server -p 1991", | ||
"test-ci": "mocha-headless-chrome -f http://localhost:1991/test/test.html" | ||
"test-ci": "mocha-headless-chrome -f http://localhost:1991/test/test.html", | ||
"start": "rocket start", | ||
"docs": "rocket build" | ||
}, | ||
@@ -34,11 +38,21 @@ "files": [ | ||
"devDependencies": { | ||
"@matthewp/compile": "^2.4.3", | ||
"@custom-elements-manifest/analyzer": "^0.4.12", | ||
"@lit/reactive-element": "^1.0.0-rc.1", | ||
"@matthewp/compile": "^3.0.0", | ||
"@rocket/cli": "^0.9.8", | ||
"@rocket/launch": "^0.5.4", | ||
"@rocket/search": "^0.4.1", | ||
"cem-plugin-jsdoc-function": "^0.0.2", | ||
"eleventy-plugin-helmet": "^0.2.2", | ||
"http-server": "^0.12.0", | ||
"mocha-headless-chrome": "^2.0.3", | ||
"typescript": "^3.6.2" | ||
"rocket-preset-code-tabs": "^0.2.2", | ||
"rocket-preset-custom-elements-manifest": "^0.1.4", | ||
"rocket-preset-playground-elements": "^0.1.2", | ||
"typescript": "^4.3.5" | ||
}, | ||
"dependencies": { | ||
"lit-html": "^1.0.0", | ||
"@lit/reactive-element": "^1.0.0-rc.2" | ||
"@lit/reactive-element": "^1.0.0-rc.2", | ||
"lit-html": "^1.0.0" | ||
} | ||
} |
63
web.js
@@ -26,2 +26,8 @@ import { directive, render } from '../lit-html/lit-html.js'; | ||
class State { | ||
update; | ||
host; | ||
virtual; | ||
[hookSymbol]; | ||
[effectsSymbol]; | ||
[layoutEffectsSymbol]; | ||
constructor(update, host) { | ||
@@ -86,2 +92,7 @@ this.update = update; | ||
class BaseScheduler { | ||
renderer; | ||
host; | ||
state; | ||
[phaseSymbol]; | ||
_updateQueued; | ||
constructor(renderer, host) { | ||
@@ -135,2 +146,3 @@ this.renderer = renderer; | ||
class Scheduler extends BaseScheduler { | ||
frag; | ||
constructor(renderer, frag, host) { | ||
@@ -148,2 +160,6 @@ super(renderer, host || frag); | ||
class Element extends BaseElement { | ||
_scheduler; | ||
static get observedAttributes() { | ||
return renderer.observedAttributes || observedAttributes || []; | ||
} | ||
constructor() { | ||
@@ -159,5 +175,2 @@ super(); | ||
} | ||
static get observedAttributes() { | ||
return renderer.observedAttributes || observedAttributes || []; | ||
} | ||
connectedCallback() { | ||
@@ -192,3 +205,5 @@ this._scheduler.update(); | ||
value = newValue; | ||
this._scheduler.update(); | ||
if (this._scheduler) { | ||
this._scheduler.update(); | ||
} | ||
} | ||
@@ -237,2 +252,4 @@ }); | ||
class Hook { | ||
id; | ||
state; | ||
constructor(id, state) { | ||
@@ -259,2 +276,6 @@ this.id = id; | ||
return hook(class extends Hook { | ||
callback; | ||
lastValues; | ||
values; | ||
_teardown; | ||
constructor(id, state, ignored1, ignored2) { | ||
@@ -292,5 +313,15 @@ super(id, state); | ||
} | ||
/** | ||
* @function | ||
* @param {() => void} effect - callback function that runs each time dependencies change | ||
* @param {unknown[]} [dependencies] - list of dependencies to the effect | ||
* @return {void} | ||
*/ | ||
const useEffect = createEffect(setEffects); | ||
const useContext = hook(class extends Hook { | ||
Context; | ||
value; | ||
_ranEffect; | ||
_unsubscribe; | ||
constructor(id, state, _) { | ||
@@ -332,3 +363,3 @@ super(id, state); | ||
cancelable: true, | ||
composed: true, | ||
composed: true, // to pass ShadowDOM boundaries | ||
})); | ||
@@ -350,2 +381,4 @@ const { unsubscribe = null, value } = detail; | ||
Provider: class extends HTMLElement { | ||
listeners; | ||
_value; | ||
constructor() { | ||
@@ -392,2 +425,4 @@ super(); | ||
const useMemo = hook(class extends Hook { | ||
value; | ||
values; | ||
constructor(id, state, fn, values) { | ||
@@ -417,3 +452,10 @@ super(id, state); | ||
/** | ||
* @function | ||
* @template {*} T | ||
* @param {T} [initialState] - Optional initial state | ||
* @return {readonly [state: T, updaterFn: StateUpdater<T>]} stateTuple - Tuple of current state and state updater function | ||
*/ | ||
const useState = hook(class extends Hook { | ||
args; | ||
constructor(id, state, initialValue) { | ||
@@ -455,7 +497,11 @@ super(id, state); | ||
class HauntedControllerHost { | ||
count; | ||
kick; | ||
_controllers = []; | ||
_updatePending = true; | ||
_updateCompletePromise; | ||
_resolveUpdate; | ||
constructor(count, kick) { | ||
this.count = count; | ||
this.kick = kick; | ||
this._controllers = []; | ||
this._updatePending = true; | ||
this._updateCompletePromise = new Promise(res => { | ||
@@ -534,2 +580,4 @@ this._resolveUpdate = res; | ||
const useReducer = hook(class extends Hook { | ||
reducer; | ||
currentState; | ||
constructor(id, state, _, initialState, init) { | ||
@@ -565,2 +613,3 @@ super(id, state); | ||
class Scheduler extends BaseScheduler { | ||
args; | ||
constructor(renderer, part) { | ||
@@ -567,0 +616,0 @@ super(renderer, part); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98471
2192
14