From 085b0215dd71ebd2a7c50bb15fd99268269675a8 Mon Sep 17 00:00:00 2001 From: kiruse <26940742+Kiruse@users.noreply.github.com> Date: Thu, 8 Dec 2022 17:53:13 +0100 Subject: [PATCH] fix null/undefined error & export utility functions --- src/store/transactional.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/store/transactional.ts b/src/store/transactional.ts index 4d0b01e..08c12d6 100644 --- a/src/store/transactional.ts +++ b/src/store/transactional.ts @@ -134,7 +134,7 @@ export class TransactionalLens { get data() { return this.db.data.getIn([...this.prefix]) as Immutify } } -function toImmutable(value: any): any { +export function toImmutable(value: any): any { // passthru Immutable collections if (isCollection(value)) return value; @@ -150,7 +150,7 @@ function toImmutable(value: any): any { // recurse into arrays & objects, converting them to lists & maps // skip primitives & objects that don't want to be touched - if (typeof value === 'object' && !(NEVER_IMMUTIFY in value)) { + if (value && typeof value === 'object' && !(NEVER_IMMUTIFY in value)) { if (isArrayLike(value)) { return List(value.map(item => toImmutable(item))); } else { @@ -165,7 +165,7 @@ function toImmutable(value: any): any { return value; } -function fromImmutable(value: any): any { +export function fromImmutable(value: any): any { // reverse Immutable maps & lists if (isMap(value)) { return fromImmutable(value.toObject()); @@ -179,7 +179,7 @@ function fromImmutable(value: any): any { // revert objects & arrays // but: passthru objects w/ NEVER_IMMUTIFY - if (typeof value === 'object' && !(NEVER_IMMUTIFY in value)) { + if (value && typeof value === 'object' && !(NEVER_IMMUTIFY in value)) { if (typeof value.length === 'number' && 0 in value && value.length-1 in value) { for (let i = 0; i < value.length; ++i) { value[i] = fromImmutable(value[i]);