From 3aad04d977b6f85b746ea42750b5494f53ef113c Mon Sep 17 00:00:00 2001 From: cesarParra Date: Sat, 7 Dec 2024 07:03:49 -0400 Subject: [PATCH] Minor refactorings --- .../signals/__tests__/signal-identity.test.ts | 18 +++++++++--------- src/lwc/signals/core.ts | 10 ++++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/lwc/signals/__tests__/signal-identity.test.ts b/src/lwc/signals/__tests__/signal-identity.test.ts index 639dc71..10bf381 100644 --- a/src/lwc/signals/__tests__/signal-identity.test.ts +++ b/src/lwc/signals/__tests__/signal-identity.test.ts @@ -1,38 +1,38 @@ -import { $signal, isASignal } from "../core"; +import { $signal, isSignal } from "../core"; describe("isASignal", () => { test("checks that a value is a signal", () => { const signal = $signal(0); - expect(isASignal(signal)).toBe(true); + expect(isSignal(signal)).toBe(true); }); test("checks that a computed is a signal", () => { const signal = $signal(0); const computed = $signal(() => signal.value); - expect(isASignal(computed)).toBe(true); + expect(isSignal(computed)).toBe(true); }); test("checks that a value is not a signal", () => { - expect(isASignal(0)).toBe(false); + expect(isSignal(0)).toBe(false); }); test("checks that a function is not a signal", () => { - expect(isASignal(() => {})).toBe(false); + expect(isSignal(() => {})).toBe(false); }); test("checks that an object is not a signal", () => { - expect(isASignal({})).toBe(false); + expect(isSignal({})).toBe(false); }); test("checks that an array is not a signal", () => { - expect(isASignal([])).toBe(false); + expect(isSignal([])).toBe(false); }); test("checks that undefined is not a signal", () => { - expect(isASignal(undefined)).toBe(false); + expect(isSignal(undefined)).toBe(false); }); test("checks that null is not a signal", () => { - expect(isASignal(null)).toBe(false); + expect(isSignal(null)).toBe(false); }); }); diff --git a/src/lwc/signals/core.ts b/src/lwc/signals/core.ts index 9fa1aef..3cdead9 100644 --- a/src/lwc/signals/core.ts +++ b/src/lwc/signals/core.ts @@ -246,6 +246,8 @@ class TrackedState implements TrackableState { } } +const SIGNAL_OBJECT_BRAND = Symbol.for("lwc-signals"); + /** * Creates a new signal with the provided value. A signal is a reactive * primitive that can be used to store and update values. Signals can be @@ -331,7 +333,7 @@ function $signal( setter(newValue); } }, - brand: Symbol.for("lwc-signals"), + brand: SIGNAL_OBJECT_BRAND, readOnly: { get value() { return getter(); @@ -534,8 +536,8 @@ function $resource( }; } -function isASignal(anything: unknown): anything is Signal { - return !!anything && (anything as Signal).brand === Symbol.for("lwc-signals"); +function isSignal(anything: unknown): anything is Signal { + return !!anything && (anything as Signal).brand === SIGNAL_OBJECT_BRAND; } -export { $signal, $effect, $computed, $resource, isASignal }; +export { $signal, $effect, $computed, $resource, isSignal };