Skip to content

Commit

Permalink
Merge pull request #57 from cloudnc/fix/lodash-es-dependency
Browse files Browse the repository at this point in the history
fix(lib): lodash-es dependency
  • Loading branch information
maxime1992 authored Jun 18, 2019
2 parents 309870f + 05f155d commit e1ba611
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion projects/ngx-sub-form/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"dest": "../../dist/ngx-sub-form",
"lib": {
"entryFile": "src/public_api.ts"
}
},
"whitelistedNonPeerDependencies": ["lodash-es"]
}
3 changes: 3 additions & 0 deletions projects/ngx-sub-form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "ngx-sub-form",
"version": "0.0.1",
"license": "MIT",
"dependencies": {
"lodash-es": "^4.17.0"
},
"peerDependencies": {
"@angular/common": "^8.0.0",
"@angular/core": "^8.0.0"
Expand Down
7 changes: 3 additions & 4 deletions projects/ngx-sub-form/src/lib/ngx-root-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { EventEmitter, OnInit, Input } from '@angular/core';
import isEqual from 'lodash-es/isEqual';
import { BehaviorSubject, Subject } from 'rxjs';
import { filter, tap } from 'rxjs/operators';
import { isNil } from 'lodash-es';
import { NgxSubFormRemapComponent } from './ngx-sub-form.component';
import { takeUntilDestroyed } from './ngx-sub-form-utils';
import { takeUntilDestroyed, isNullOrUndefined } from './ngx-sub-form-utils';

export abstract class NgxRootFormComponent<ControlInterface, FormInterface = ControlInterface>
extends NgxSubFormRemapComponent<ControlInterface, FormInterface>
Expand Down Expand Up @@ -44,7 +43,7 @@ export abstract class NgxRootFormComponent<ControlInterface, FormInterface = Con
.pipe(
filter(newValue => !isEqual(newValue, this.formGroup.value)),
tap(newValue => {
if (!isNil(newValue)) {
if (!isNullOrUndefined(newValue)) {
this.writeValue(newValue);
}
}),
Expand Down Expand Up @@ -90,7 +89,7 @@ export abstract class NgxRootFormComponent<ControlInterface, FormInterface = Con
}

public manualSave(): void {
if (!isNil(this.dataValue)) {
if (!isNullOrUndefined(this.dataValue)) {
this._dataOutput$.next(this.dataValue);
}
}
Expand Down
5 changes: 5 additions & 0 deletions projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,8 @@ export function takeUntilDestroyed<T>(component: OnDestroy): (source: Observable
return source.pipe(takeUntil(onDestroy));
};
}

/** @internal */
export function isNullOrUndefined(obj: any): obj is null | undefined {
return obj === null || obj === undefined;
}
6 changes: 3 additions & 3 deletions projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
MissingFormControlsError,
ArrayNotTransformedBeforeWriteValueError,
FormErrors,
isNullOrUndefined,
} from './ngx-sub-form-utils';
import { FormGroupOptions, OnFormUpdate, TypedFormGroup } from './ngx-sub-form.types';
import { isNil } from 'lodash-es';

type MapControlFunction<FormInterface, MapValue> = (ctrl: AbstractControl, key: keyof FormInterface) => MapValue;
type FilterControlFunction<FormInterface> = (ctrl: AbstractControl, key: keyof FormInterface) => boolean;
Expand Down Expand Up @@ -182,7 +182,7 @@ export abstract class NgxSubFormComponent<ControlInterface, FormInterface = Cont
// if the value is null or undefined it might be because we're
// switching from one value of a polymorphic type to another
// for ex and in that case we don't want to go further
if (isNil(obj)) {
if (isNullOrUndefined(obj)) {
return;
}

Expand Down Expand Up @@ -210,7 +210,7 @@ export abstract class NgxSubFormComponent<ControlInterface, FormInterface = Cont
// `controlKeys` can be an empty array, empty forms are allowed
const missingKeys: (keyof FormInterface)[] = this.controlKeys.reduce(
(keys, key) => {
if (isNil(transformedValue) || transformedValue[key] === undefined) {
if (isNullOrUndefined(transformedValue) || transformedValue[key] === undefined) {
keys.push(key);
}

Expand Down

0 comments on commit e1ba611

Please sign in to comment.