Skip to content

Commit

Permalink
fix null/undefined error & export utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiruse committed Dec 8, 2022
1 parent 352983e commit 085b021
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/store/transactional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class TransactionalLens<M extends object> {
get data() { return this.db.data.getIn([...this.prefix]) as Immutify<M> }
}

function toImmutable(value: any): any {
export function toImmutable(value: any): any {
// passthru Immutable collections
if (isCollection(value)) return value;

Expand All @@ -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 {
Expand All @@ -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());
Expand All @@ -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]);
Expand Down

0 comments on commit 085b021

Please sign in to comment.