Skip to content

Commit

Permalink
feat(signals): remove selectSignal and rename withSignals to withComp…
Browse files Browse the repository at this point in the history
…uted (#4075)
  • Loading branch information
markostanimirovic authored Oct 19, 2023
1 parent 3dbcadc commit 25f95bc
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 338 deletions.
208 changes: 0 additions & 208 deletions modules/signals/spec/select-signal.spec.ts

This file was deleted.

13 changes: 6 additions & 7 deletions modules/signals/spec/signal-store-feature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Signal, signal } from '@angular/core';
import { computed, Signal, signal } from '@angular/core';
import {
selectSignal,
signalStore,
signalStoreFeature,
type,
withComputed,
withMethods,
withSignals,
withState,
} from '../src';
import { STATE_SIGNAL } from '../src/signal-state';
Expand All @@ -14,7 +13,7 @@ describe('signalStoreFeature', () => {
function withCustomFeature1() {
return signalStoreFeature(
withState({ foo: 'foo' }),
withSignals(({ foo }) => ({ bar: selectSignal(() => foo() + 1) })),
withComputed(({ foo }) => ({ bar: computed(() => foo() + 1) })),
withMethods(({ foo, bar }) => ({
baz: () => foo() + bar() + 2,
}))
Expand Down Expand Up @@ -45,8 +44,8 @@ describe('signalStoreFeature', () => {
it('creates a custom feature by combining base features', () => {
const Store = signalStore(
withCustomFeature1(),
withSignals(({ bar }) => ({
s: selectSignal(() => bar() + 's'),
withComputed(({ bar }) => ({
s: computed(() => bar() + 's'),
}))
);

Expand Down Expand Up @@ -77,7 +76,7 @@ describe('signalStoreFeature', () => {
it('creates a custom feature with input', () => {
const Store = signalStore(
withCustomFeature1(),
withSignals(() => ({ s: signal(1).asReadonly() })),
withComputed(() => ({ s: signal(1).asReadonly() })),
withCustomFeatureWithInput()
);

Expand Down
20 changes: 10 additions & 10 deletions modules/signals/spec/signal-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { inject, InjectionToken, isSignal, signal } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import {
signalStore,
withComputed,
withHooks,
withMethods,
withSignals,
withState,
} from '../src';
import { STATE_SIGNAL } from '../src/signal-state';
Expand Down Expand Up @@ -84,12 +84,12 @@ describe('signalStore', () => {
});
});

describe('withSignals', () => {
describe('withComputed', () => {
it('provides previously defined state slices and computed signals as input argument', () => {
const Store = signalStore(
withState(() => ({ foo: 'foo' })),
withSignals(() => ({ bar: signal('bar').asReadonly() })),
withSignals(({ foo, bar }) => {
withComputed(() => ({ bar: signal('bar').asReadonly() })),
withComputed(({ foo, bar }) => {
expect(foo()).toBe('foo');
expect(bar()).toBe('bar');

Expand All @@ -105,12 +105,12 @@ describe('signalStore', () => {
expect(store.baz()).toBe('baz');
});

it('executes withSignals factory in injection context', () => {
it('executes withComputed factory in injection context', () => {
const TOKEN = new InjectionToken('TOKEN', {
providedIn: 'root',
factory: () => ({ bar: signal('bar').asReadonly() }),
});
const Store = signalStore(withSignals(() => inject(TOKEN)));
const Store = signalStore(withComputed(() => inject(TOKEN)));

TestBed.configureTestingModule({ providers: [Store] });
const store = TestBed.inject(Store);
Expand All @@ -123,7 +123,7 @@ describe('signalStore', () => {
it('provides previously defined store properties as an input argument', () => {
const Store = signalStore(
withState(() => ({ foo: 'foo' })),
withSignals(() => ({ bar: signal('bar').asReadonly() })),
withComputed(() => ({ bar: signal('bar').asReadonly() })),
withMethods(() => ({ baz: () => 'baz' })),
withMethods((store) => {
expect(store[STATE_SIGNAL]()).toEqual({ foo: 'foo' });
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('signalStore', () => {
let message = '';
const Store = signalStore(
withState(() => ({ foo: 'foo' })),
withSignals(() => ({ bar: signal('bar').asReadonly() })),
withComputed(() => ({ bar: signal('bar').asReadonly() })),
withMethods(() => ({ baz: () => 'baz' })),
withHooks({
onInit(store) {
Expand All @@ -221,7 +221,7 @@ describe('signalStore', () => {
let message = '';
const Store = signalStore(
withState(() => ({ foo: 'foo' })),
withSignals(() => ({ bar: signal('bar').asReadonly() })),
withComputed(() => ({ bar: signal('bar').asReadonly() })),
withMethods(() => ({ baz: () => 'baz' })),
withHooks({
onDestroy(store) {
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('signalStore', () => {
it('overrides previously defined store properties immutably', () => {
const Store = signalStore(
withState({ i: 1, j: 2, k: 3, l: 4 }),
withSignals(({ i, j, k, l }) => {
withComputed(({ i, j, k, l }) => {
expect(i()).toBe(1);
expect(j()).toBe(2);
expect(k()).toBe(3);
Expand Down
Loading

0 comments on commit 25f95bc

Please sign in to comment.