@alwatr/signal
Advanced tools
Comparing version 0.30.0 to 0.31.0
@@ -6,2 +6,14 @@ # Change Log | ||
# [0.31.0](https://github.com/AliMD/alwatr/compare/v0.30.0...v0.31.0) (2023-05-08) | ||
### Bug Fixes | ||
- new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300)) | ||
- **signal:** dont receivePrevious when listener is disabled ([68ae207](https://github.com/AliMD/alwatr/commit/68ae207ce9ecf104922b24910d8dfcedb13acde7)) | ||
- **signal:** requestableContextProvider.getValue ([0a7111d](https://github.com/AliMD/alwatr/commit/0a7111da7b8eb004566922dc9b35edfc02a55147)) | ||
### Features | ||
- **signal:** new RequestableContext with state ([b8a8e55](https://github.com/AliMD/alwatr/commit/b8a8e550d3952863d85ba9d9d87513a668a9430d)) | ||
# [0.30.0](https://github.com/AliMD/alwatr/compare/v0.29.0...v0.30.0) (2023-03-06) | ||
@@ -8,0 +20,0 @@ |
@@ -104,3 +104,3 @@ import type { DispatchOptions, ListenerFunction, SubscribeOptions, SignalObject, ProviderFunction, ProviderOptions, ListenerSpec } from './type.js'; | ||
*/ | ||
export declare const setContextProvider: <TContext extends Stringifyable, TRquest extends Stringifyable>(signalId: string, signalProvider: ProviderFunction<TRquest, void | TContext>, options?: Partial<ProviderOptions>) => void; | ||
export declare const setContextProvider: <TContext extends Stringifyable, TRquest extends Stringifyable = null>(signalId: string, signalProvider: ProviderFunction<TRquest, void | TContext>, options?: Partial<ProviderOptions>) => void; | ||
/** | ||
@@ -107,0 +107,0 @@ * Defines the command and dispatch returned value. |
49
core.js
@@ -47,3 +47,4 @@ import { createLogger, globalAlwatr } from '@alwatr/logger'; | ||
export const _callListeners = (signal, detail) => { | ||
logger.logMethodArgs('_callListeners', { signalId: signal.id, signalDetail: detail }); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, '_callListeners', { signalId: signal.id, signalDetail: detail }); | ||
const removeList = []; | ||
@@ -83,3 +84,3 @@ for (const listener of signal.listenerList) { | ||
export const subscribe = (signalId, listenerCallback, options = {}) => { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e; | ||
(_a = options.once) !== null && _a !== void 0 ? _a : (options.once = false); | ||
@@ -89,3 +90,3 @@ (_b = options.disabled) !== null && _b !== void 0 ? _b : (options.disabled = false); | ||
(_d = options.priority) !== null && _d !== void 0 ? _d : (options.priority = false); | ||
logger.logMethodArgs('subscribe', { signalId, options }); | ||
(_e = logger.logMethodArgs) === null || _e === void 0 ? void 0 : _e.call(logger, 'subscribe', { signalId, options }); | ||
const signal = getSignalObject(signalId); | ||
@@ -99,4 +100,4 @@ const listener = { | ||
}; | ||
const callbackCall = signal.detail !== undefined && options.receivePrevious !== 'No'; | ||
if (callbackCall) { | ||
const execCallback = signal.detail !== undefined && options.receivePrevious !== 'No' && options.disabled !== true; | ||
if (execCallback) { | ||
// Run callback for old dispatch signal | ||
@@ -122,3 +123,3 @@ const callback = () => { | ||
// if once then must remove listener after fist callback called! then why push it to listenerList?! | ||
if (!(callbackCall && options.once)) { | ||
if (!(execCallback && options.once)) { | ||
if (options.priority === true) { | ||
@@ -148,3 +149,4 @@ signal.listenerList.unshift(listener); | ||
export const unsubscribe = (listener) => { | ||
logger.logMethodArgs('unsubscribe', listener); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'unsubscribe', listener); | ||
const signal = getSignalObject(listener.signalId); | ||
@@ -166,3 +168,4 @@ const listenerIndex = signal.listenerList.findIndex((_listener) => _listener.id === listener.id); | ||
export const removeAllListeners = (signalId) => { | ||
logger.logMethodArgs('removeAllListeners', signalId); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'removeAllListeners', signalId); | ||
const signal = getSignalObject(signalId); | ||
@@ -186,5 +189,5 @@ if (signal.listenerList.length === 0) | ||
export const dispatch = (signalId, detail, options = {}) => { | ||
var _a; | ||
var _a, _b; | ||
(_a = options.debounce) !== null && _a !== void 0 ? _a : (options.debounce = 'AnimationFrame'); | ||
logger.logMethodArgs('dispatch', { signalId, detail, options }); | ||
(_b = logger.logMethodArgs) === null || _b === void 0 ? void 0 : _b.call(logger, 'dispatch', { signalId, detail, options }); | ||
const signal = getSignalObject(signalId); | ||
@@ -246,3 +249,4 @@ // set detail before check signal.debounced for act like throttle (call listeners with last dispatch detail). | ||
return new Promise((resolve) => { | ||
logger.logMethodArgs('untilNext', signalId); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'untilNext', signalId); | ||
subscribe(signalId, resolve, { | ||
@@ -266,6 +270,6 @@ once: true, | ||
export const setContextProvider = (signalId, signalProvider, options = {}) => { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
(_a = options.debounce) !== null && _a !== void 0 ? _a : (options.debounce = 'AnimationFrame'); | ||
(_b = options.receivePrevious) !== null && _b !== void 0 ? _b : (options.receivePrevious = 'AnimationFrame'); | ||
logger.logMethodArgs('setContextProvider', { signalId, options }); | ||
(_c = logger.logMethodArgs) === null || _c === void 0 ? void 0 : _c.call(logger, 'setContextProvider', { signalId, options }); | ||
const requestSignalId = 'request-' + signalId; | ||
@@ -299,5 +303,5 @@ removeAllListeners(requestSignalId); | ||
export const defineCommand = (signalId, signalProvider, options = {}) => { | ||
var _a; | ||
var _a, _b; | ||
(_a = options.debounce) !== null && _a !== void 0 ? _a : (options.debounce = 'AnimationFrame'); | ||
logger.logMethodArgs('defineCommand', { commandId: signalId, options }); | ||
(_b = logger.logMethodArgs) === null || _b === void 0 ? void 0 : _b.call(logger, 'defineCommand', { commandId: signalId, options }); | ||
const requestSignalId = 'request-' + signalId; | ||
@@ -327,3 +331,4 @@ removeAllListeners(requestSignalId); | ||
export const requestContext = (contextId, requestParam, options = {}) => { | ||
logger.logMethodArgs('requestContext', { contextId, requestParam }); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'requestContext', { contextId, requestParam }); | ||
return dispatch(`request-${contextId}`, requestParam, options); | ||
@@ -341,3 +346,4 @@ }; | ||
export const requestCommand = (commandId, commandArgument) => { | ||
logger.logMethodArgs('requestCommand', { commandId, commandArgument }); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'requestCommand', { commandId, commandArgument }); | ||
dispatch(`request-${commandId}`, commandArgument, { debounce: 'No' }); | ||
@@ -357,3 +363,4 @@ }; | ||
export const requestCommandWithResponse = async (commandId, commandArgument) => { | ||
logger.logMethodArgs('requestCommand', { commandId, commandArgument }); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'requestCommand', { commandId, commandArgument }); | ||
const _requestSignalId = `request-${commandId}`; | ||
@@ -382,3 +389,4 @@ const _callbackSignalId = `callback-${commandId}-${++_lastListenerAutoId}`; | ||
export const clearDetail = (signalId) => { | ||
logger.logMethodArgs('expire', signalId); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'expire', signalId); | ||
const signal = getSignalObject(signalId); | ||
@@ -399,3 +407,4 @@ delete signal.detail; | ||
export const destroySignal = (signalId) => { | ||
logger.logMethodArgs('destroySignal', signalId); | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'destroySignal', signalId); | ||
const signal = _signalStorage[signalId]; | ||
@@ -402,0 +411,0 @@ if (signal == null) |
{ | ||
"name": "@alwatr/signal", | ||
"version": "0.30.0", | ||
"version": "0.31.0", | ||
"description": "Elegant powerful event system for handle global signals and states written in tiny TypeScript module.", | ||
@@ -32,8 +32,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@alwatr/logger": "^0.30.0", | ||
"@alwatr/type": "^0.30.0", | ||
"@alwatr/util": "^0.30.0", | ||
"@alwatr/logger": "^0.31.0", | ||
"@alwatr/type": "^0.31.0", | ||
"@alwatr/util": "^0.31.0", | ||
"tslib": "^2.5.0" | ||
}, | ||
"gitHead": "36f55780ccdcb1acc07400b0cdb3fe7b0df56cca" | ||
"gitHead": "896e64b58eed6e9048e870557ecf399d42705612" | ||
} |
@@ -0,1 +1,2 @@ | ||
import { RequestableContext } from './type.js'; | ||
import type { Stringifyable } from '@alwatr/type'; | ||
@@ -13,3 +14,3 @@ /** | ||
* requestableContextConsumer.request<RequestParamType>('product-list', {foo: 'bar'}); | ||
* const newProductList = await requestableContextConsumer.untilChange<ProductListType>('product-list'); | ||
* TODO: update me | ||
* ``` | ||
@@ -27,4 +28,15 @@ */ | ||
*/ | ||
readonly bind: <TContext extends Stringifyable, TRquest extends Stringifyable>(contextId: string) => { | ||
readonly bind: <TContextContent extends Stringifyable, TRquest extends Stringifyable = null>(contextId: string) => { | ||
/** | ||
* Get context value. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* const currentProductList = productListConsumer.getValue(); | ||
* TODO: update me | ||
* ``` | ||
*/ | ||
readonly getValue: () => RequestableContext<TContextContent>; | ||
/** | ||
* Send new context request to the provider. | ||
@@ -36,3 +48,3 @@ * | ||
* productListConsumer.request({foo: 'bar'}); | ||
* const newProductList = await productListConsumer.untilChange(); | ||
* TODO: update me | ||
* ``` | ||
@@ -42,5 +54,4 @@ */ | ||
readonly id: string; | ||
readonly getValue: () => TContext | undefined; | ||
readonly untilChange: () => Promise<TContext>; | ||
readonly subscribe: (listenerCallback: import("./type.js").ListenerFunction<TContext>, options?: Partial<import("./type.js").SubscribeOptions> | undefined) => import("./type.js").ListenerSpec; | ||
readonly untilChange: () => Promise<RequestableContext<TContextContent>>; | ||
readonly subscribe: (listenerCallback: import("./type.js").ListenerFunction<RequestableContext<TContextContent>>, options?: Partial<import("./type.js").SubscribeOptions> | undefined) => import("./type.js").ListenerSpec; | ||
readonly unsubscribe: (listener: import("./type.js").ListenerSpec) => void; | ||
@@ -47,0 +58,0 @@ }; |
import { contextConsumer } from './context-consumer.js'; | ||
import { requestContext } from './core.js'; | ||
import { getDetail, requestContext } from './core.js'; | ||
/** | ||
@@ -15,3 +15,3 @@ * Requestable context consumer interface. | ||
* requestableContextConsumer.request<RequestParamType>('product-list', {foo: 'bar'}); | ||
* const newProductList = await requestableContextConsumer.untilChange<ProductListType>('product-list'); | ||
* TODO: update me | ||
* ``` | ||
@@ -32,2 +32,13 @@ */ | ||
/** | ||
* Get context value. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* const currentProductList = productListConsumer.getValue(); | ||
* TODO: update me | ||
* ``` | ||
*/ | ||
getValue: () => { var _a; return (_a = getDetail(contextId)) !== null && _a !== void 0 ? _a : { state: 'initial' }; }, | ||
/** | ||
* Send new context request to the provider. | ||
@@ -39,3 +50,3 @@ * | ||
* productListConsumer.request({foo: 'bar'}); | ||
* const newProductList = await productListConsumer.untilChange(); | ||
* TODO: update me | ||
* ``` | ||
@@ -42,0 +53,0 @@ */ |
@@ -0,1 +1,2 @@ | ||
import { RequestableContext } from './type.js'; | ||
import type { Stringifyable } from '@alwatr/type'; | ||
@@ -22,3 +23,3 @@ /** | ||
*/ | ||
readonly setProvider: <TContext extends Stringifyable, TRquest extends Stringifyable>(signalId: string, signalProvider: import("./type.js").ProviderFunction<TRquest, void | TContext>, options?: Partial<import("./type.js").ProviderOptions>) => void; | ||
readonly setProvider: <TContext extends Stringifyable, TRquest extends Stringifyable = null>(signalId: string, signalProvider: import("./type.js").ProviderFunction<TRquest, void | TContext>, options?: Partial<import("./type.js").ProviderOptions>) => void; | ||
/** | ||
@@ -33,4 +34,15 @@ * Bind this interface to special context. | ||
*/ | ||
readonly bind: <TContext_1 extends Stringifyable, TRquest_1 extends Stringifyable>(contextId: string) => { | ||
readonly bind: <TContextContent extends Stringifyable, TRquest_1 extends Stringifyable = null>(contextId: string) => { | ||
/** | ||
* Get context value. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* const currentProductList = productListConsumer.getValue(); | ||
* TODO: update me | ||
* ``` | ||
*/ | ||
readonly getValue: () => RequestableContext<TContextContent>; | ||
/** | ||
* Defines the provider of the context signal that will be called when the context requested. | ||
@@ -48,8 +60,7 @@ * | ||
*/ | ||
readonly setProvider: (signalProvider: import("./type.js").ProviderFunction<TRquest_1, void | TContext_1>, options?: Partial<import("./type.js").ProviderOptions> | undefined) => void; | ||
readonly setProvider: (signalProvider: import("./type.js").ProviderFunction<TRquest_1, void | RequestableContext<TContextContent>>, options?: Partial<import("./type.js").ProviderOptions> | undefined) => void; | ||
readonly id: string; | ||
readonly getValue: () => TContext_1 | undefined; | ||
readonly setValue: (detail: TContext_1, options?: Partial<import("./type.js").DispatchOptions> | undefined) => void; | ||
readonly setValue: (detail: RequestableContext<TContextContent>, options?: Partial<import("./type.js").DispatchOptions> | undefined) => void; | ||
readonly expire: () => void; | ||
readonly untilChange: () => Promise<TContext_1>; | ||
readonly untilChange: () => Promise<RequestableContext<TContextContent>>; | ||
}; | ||
@@ -56,0 +67,0 @@ readonly getValue: <T extends Stringifyable>(signalId: string) => T | undefined; |
import { contextProvider } from './context-provider.js'; | ||
import { setContextProvider } from './core.js'; | ||
import { getDetail, setContextProvider } from './core.js'; | ||
/** | ||
@@ -37,2 +37,13 @@ * Requestable context provider interface. | ||
/** | ||
* Get context value. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* const currentProductList = productListConsumer.getValue(); | ||
* TODO: update me | ||
* ``` | ||
*/ | ||
getValue: () => { var _a; return (_a = getDetail(contextId)) !== null && _a !== void 0 ? _a : { state: 'initial' }; }, | ||
/** | ||
* Defines the provider of the context signal that will be called when the context requested. | ||
@@ -39,0 +50,0 @@ * |
@@ -133,2 +133,15 @@ import type { MaybePromise, Stringifyable } from '@alwatr/type'; | ||
export type SignalStorage = Record<string, SignalObject<Stringifyable> | undefined>; | ||
/** | ||
* Requestable context value type. | ||
*/ | ||
export type RequestableContext<T extends Stringifyable> = { | ||
state: 'initial' | 'pending'; | ||
content?: never; | ||
} | { | ||
state: 'error'; | ||
content?: T; | ||
} | { | ||
state: 'complete' | 'reloading'; | ||
content: T; | ||
}; | ||
//# sourceMappingURL=type.d.ts.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
137380
2037
+ Added@alwatr/logger@0.31.0(transitive)
+ Added@alwatr/math@0.31.0(transitive)
+ Added@alwatr/type@0.31.0(transitive)
+ Added@alwatr/util@0.31.0(transitive)
- Removed@alwatr/logger@0.30.0(transitive)
- Removed@alwatr/math@0.30.0(transitive)
- Removed@alwatr/type@0.30.0(transitive)
- Removed@alwatr/util@0.30.0(transitive)
Updated@alwatr/logger@^0.31.0
Updated@alwatr/type@^0.31.0
Updated@alwatr/util@^0.31.0