Skip to content

Commit

Permalink
createEffect.forValue() renamed to getEffectFor().
Browse files Browse the repository at this point in the history
  • Loading branch information
e-oz committed Sep 5, 2024
1 parent ed19fd9 commit c267cb2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 4.2.2
`createEffect.forValue()` renamed to `getEffectFor()`.

### 4.2.1
Experimental method for `createEffect()`: `forValue()`, which takes a value and returns an observable that will execute the effect when subscribed.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-collection",
"version": "4.2.1",
"version": "4.2.2",
"license": "MIT",
"author": {
"name": "Evgeniy OZ",
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-collection/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-collection",
"version": "4.2.1",
"version": "4.2.2",
"license": "MIT",
"author": {
"name": "Evgeniy OZ",
Expand All @@ -17,7 +17,7 @@
],
"private": false,
"peerDependencies": {
"@angular/core": "^17 || ^18 || ~19.0.0-next.2",
"@angular/core": "^17 || ^18 || ~19.0.0-next.3",
"rxjs": "^7 || ^8"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions projects/ngx-collection/src/lib/create-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type CreateEffectOptions = {
export type EffectMethods<ObservableType> = {
next$: Observable<unknown>,
error$: Observable<unknown>,
forValue: (observableOrValue?: ObservableType | Observable<ObservableType> | Signal<ObservableType>) => Observable<unknown>,
getEffectFor: (observableOrValue?: ObservableType | Observable<ObservableType> | Signal<ObservableType>) => Observable<unknown>,
};

export type EffectListeners = {
Expand Down Expand Up @@ -141,8 +141,8 @@ export function createEffect<
configurable: false
});

Object.defineProperty(effectFn, 'forValue', {
get: () => (observableOrValue?: ObservableType | Observable<ObservableType> | Signal<ObservableType>) => () => {
Object.defineProperty(effectFn, 'getEffectFor', {
get: () => (observableOrValue?: ObservableType | Observable<ObservableType> | Signal<ObservableType>) => {
const observable$ = isObservable(observableOrValue)
? observableOrValue
: (isSignal(observableOrValue)
Expand Down
11 changes: 9 additions & 2 deletions projects/ngx-collection/src/lib/tests/create-effect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { signal } from "@angular/core";
import { TestBed } from "@angular/core/testing";
import { EMPTY, of, Subject, switchMap, tap, throwError } from "rxjs";
import { EMPTY, isObservable, of, Subject, switchMap, tap, throwError } from "rxjs";
import { createEffect } from '../create-effect';

describe('createEffect', () => {
Expand Down Expand Up @@ -135,5 +135,12 @@ describe('createEffect', () => {
TestBed.flushEffects();
expect(lastResult).toEqual('c');
expect(lastError).toEqual(undefined);
})
});

it('should return an observable when getEffectFor() is called', () => {
const e = effect.getEffectFor('test');
expect(isObservable(e)).toEqual(true);
e.subscribe();
expect(lastResult).toEqual('test');
});
});

0 comments on commit c267cb2

Please sign in to comment.