Skip to content

Commit

Permalink
chore(*): update internal deps (#112)
Browse files Browse the repository at this point in the history
* chore(*): update internal deps

* chore(*): update internal deps
  • Loading branch information
MM25Zamanian authored May 25, 2024
1 parent 97cc026 commit 0e253e2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/logger/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class GecutLogger {
timeEnd?: (label: string) => void;

sub(domain: string, _devMode = this.devMode) {
return new GecutLogger(`${this.domain} ${domain}`, _devMode);
return new GecutLogger(`${this.domain}${domain}`, _devMode);
}

private static stabilizeDomain(domain: string): string {
Expand Down
3 changes: 2 additions & 1 deletion packages/signal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"directory": "packages/signal"
},
"dependencies": {
"@gecut/logger": "workspace:^"
"@gecut/logger": "workspace:^",
"@gecut/types": "workspace:^"
}
}
32 changes: 11 additions & 21 deletions packages/signal/src/libraries/_signal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GecutLogger } from '@gecut/logger';
import {GecutLogger} from '@gecut/logger';

import type { SubscribeOptions, Subscriber } from '../type.js';
import type {SubscribeOptions, Subscriber} from '../type.js';

/**
* A Signal object allows for subscribing to notifications with callbacks.
Expand All @@ -17,7 +17,7 @@ export abstract class Signal<T> {
options: Required<SubscribeOptions>;
}[] = [];

protected value?: T;
protected value: T | undefined;
protected hasDispatched = false;
protected log: GecutLogger;

Expand All @@ -26,11 +26,9 @@ export abstract class Signal<T> {
* @param {Subscriber<T>} callback - The callback to unsubscribe.
*/
unsubscribe(callback: Subscriber<T>): void {
this.log.methodArgs?.('unsubscribe', { callback });
this.log.methodArgs?.('unsubscribe', {callback});

this.subscribers = this.subscribers.filter(
(subscriber) => subscriber.callback !== callback
);
this.subscribers = this.subscribers.filter((subscriber) => subscriber.callback !== callback);
}

/**
Expand All @@ -40,36 +38,28 @@ export abstract class Signal<T> {
* @return {unknown} The `subscribe` method returns an object with a single property `unsubscribe`, which is a
* function that can be called to unsubscribe from the subscription.
*/
subscribe(
callback: Subscriber<T>,
options: SubscribeOptions = {}
): { unsubscribe: () => void } {
subscribe(callback: Subscriber<T>, options: SubscribeOptions = {}): {unsubscribe: () => void} {
const resolvedOptions: Required<SubscribeOptions> = {
once: false,
priority: 0,
disabled: false,
receivePrevious: false,
...options
...options,
};

const newSubscriber = { callback, options: resolvedOptions };
const newSubscriber = {callback, options: resolvedOptions};

this.log.methodArgs?.('subscribe', newSubscriber);

this.subscribers.push(newSubscriber);
this.subscribers.sort((a, b) => b.options.priority - a.options.priority);

if (
resolvedOptions.receivePrevious &&
this.hasDispatched &&
this.value &&
!resolvedOptions.disabled
) {
if (resolvedOptions.receivePrevious && this.hasDispatched && this.value && !resolvedOptions.disabled) {
callback(this.value);
}

return {
unsubscribe: this.unsubscribe.bind(this, callback)
unsubscribe: this.unsubscribe.bind(this, callback),
};
}

Expand Down Expand Up @@ -103,7 +93,7 @@ export abstract class Signal<T> {
this.subscribe(resolve, {
once: true,
priority: 1_000,
receivePrevious: false
receivePrevious: false,
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/signal/src/libraries/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class ContextSignal<T> extends Signal<T> {

const value = this.getValue();

if (value) {
this.setValue(value);
if (this.hasDispatched) {
this.setValue(value as T);
}
}
}
2 changes: 1 addition & 1 deletion packages/signal/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

"include": ["src/**/*.ts"],
"exclude": [],
"references": [{"path": "../logger"}]
"references": [{"path": "../logger"}, {"path": "../types"}]
}
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ __metadata:
resolution: "@gecut/signal@workspace:packages/signal"
dependencies:
"@gecut/logger": "workspace:^"
"@gecut/types": "workspace:^"
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 0e253e2

Please sign in to comment.