From 265bd079d91c113102d59e7fb0192ae9f67ece26 Mon Sep 17 00:00:00 2001 From: AlexandrHoroshih Date: Thu, 12 Oct 2023 23:20:06 +0700 Subject: [PATCH] Make empty operator work with full-void stores --- src/empty/empty.fork.test.ts | 28 ++++++++++++++++++++++++++++ src/empty/index.ts | 4 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/empty/empty.fork.test.ts b/src/empty/empty.fork.test.ts index 95dbab25..542f99d2 100644 --- a/src/empty/empty.fork.test.ts +++ b/src/empty/empty.fork.test.ts @@ -26,3 +26,31 @@ test('numbers', async () => { await allSettled(increment, { scope }); expect(scope.getState($result)).toBe(false); }); + +test('strings', async () => { + const set = createEvent(); + const $str = createStore('').on(set, (_, str) => str); + const $empty = empty($str); + + const scope = fork(); + + expect(scope.getState($empty)).toBe(false); + + allSettled(set, { scope, params: 'hello' }); + + expect(scope.getState($empty)).toBe(false); +}) + +test('void', async () => { + const set = createEvent(); + const $str = createStore(null, {skipVoid: false}).on(set, (_, str) => str); + const $empty = empty($str); + + const scope = fork(); + + expect(scope.getState($empty)).toBe(true); + + allSettled(set, { scope, params: undefined }); + + expect(scope.getState($empty)).toBe(true); +}); diff --git a/src/empty/index.ts b/src/empty/index.ts index 8e5e7908..4f272667 100644 --- a/src/empty/index.ts +++ b/src/empty/index.ts @@ -1,5 +1,5 @@ import { Store } from 'effector'; -export function empty(source: Store): Store { - return source.map((value) => value === null); +export function empty(source: Store): Store { + return source.map((value) => value == null); }