Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(signals): remove selectSignal and rename withSignals to withComputed #4075

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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