Skip to content

Commit

Permalink
feat: split old and new API so that we can access them with ngx-sub-f…
Browse files Browse the repository at this point in the history
…orm and ngx-sub-form/new to avoid making a breaking change
  • Loading branch information
maxime1992 committed Sep 13, 2020
1 parent 12d12b3 commit 3db939b
Show file tree
Hide file tree
Showing 30 changed files with 62 additions and 65 deletions.
8 changes: 8 additions & 0 deletions projects/ngx-sub-form/new/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/ngx-sub-form",
"lib": {
"entryFile": "../public_api.new.ts"
},
"whitelistedNonPeerDependencies": ["fast-deep-equal"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
NewFormErrors,
OneOfControlsTypes,
TypedFormGroup,
} from '../ngx-sub-form-utils';
} from '../../src/lib/shared/ngx-sub-form-utils';
import {
ControlValueAccessorComponentInstance,
FormBindings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ɵivyEnabled, ɵmarkDirty as markDirty } from '@angular/core';
import { ɵmarkDirty as markDirty } from '@angular/core';
import isEqual from 'fast-deep-equal';
import { decorateObservableLifecycle, getObservableLifecycle } from 'ngx-observable-lifecycle';
import { EMPTY, forkJoin, Observable, of } from 'rxjs';
import { delay, filter, map, mapTo, shareReplay, switchMap, take, takeUntil, tap } from 'rxjs/operators';
import { isNullOrUndefined } from '../ngx-sub-form-utils';
import { isNullOrUndefined } from '../../src/lib/shared/ngx-sub-form-utils';
import {
createFormDataFromOptions,
getControlValueAccessorBindings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
ControlsNames,
NewFormErrors,
TypedFormGroup,
} from '../ngx-sub-form-utils';
import { FormGroupOptions } from '../ngx-sub-form.types';
} from '../../src/lib/shared/ngx-sub-form-utils';
import { FormGroupOptions } from '../../src/lib/shared/ngx-sub-form.types';
import { AreTypesSimilar } from './helpers.types';

export interface ComponentHooks {
Expand Down
16 changes: 16 additions & 0 deletions projects/ngx-sub-form/public_api.new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Public API Surface of sub-form
*/

// in order to **not** bring a breaking change with the rewrite
// to allow incremental updates, we publish the library using
// 2 different paths: `ngx-sub-form` and `ngx-sub-form/new`
// as within the `new` package we use shared functionalities
// coming from the old code, we need to have the root of the lib
// higher than the `new` folder, see following issue
// https://github.com/ng-packagr/ng-packagr/issues/358#issuecomment-524504864

export * from './new/src/helpers';
export * from './new/src/helpers.types';
export * from './new/src/ngx-sub-form';
export { FormType } from './new/src/ngx-sub-form.types';
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EventEmitter, Input, Component, Output, DebugElement } from '@angular/core';
import { Controls } from './ngx-sub-form-utils';
import { FormControl, Validators, ReactiveFormsModule } from '@angular/forms';
import { BehaviorSubject } from 'rxjs';
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { Component, DebugElement, EventEmitter, Input, Output } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { DataInput } from './ngx-sub-form.decorators';
import { BehaviorSubject } from 'rxjs';
import { Controls } from '../shared/ngx-sub-form-utils';
import { NgxAutomaticRootFormComponent } from './ngx-automatic-root-form.component';
import { DataInput } from './ngx-sub-form.decorators';

interface Vehicle {
color?: string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormArray, FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { BehaviorSubject } from 'rxjs';
import { ArrayPropertyKey, ArrayPropertyValue, Controls } from '../shared/ngx-sub-form-utils';
import { NgxRootFormComponent } from './ngx-root-form.component';
import { ArrayPropertyKey, ArrayPropertyValue, Controls } from './ngx-sub-form-utils';
import { DataInput } from './ngx-sub-form.decorators';
import { NgxFormWithArrayControls } from './ngx-sub-form.types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EventEmitter, OnInit, Input, Component, Directive } from '@angular/core';
import { Directive, EventEmitter, Input, OnInit } from '@angular/core';
import isEqual from 'fast-deep-equal';
import { BehaviorSubject, Subject } from 'rxjs';
import { filter, tap } from 'rxjs/operators';
import { isNullOrUndefined, takeUntilDestroyed } from '../shared/ngx-sub-form-utils';
import { NgxSubFormRemapComponent } from './ngx-sub-form.component';
import { takeUntilDestroyed, isNullOrUndefined } from './ngx-sub-form-utils';

@Directive()
// tslint:disable-next-line: directive-class-suffix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
MissingFormControlsError,
TypedAbstractControl,
TypedFormGroup,
} from './ngx-sub-form-utils';
import { FormGroupOptions, NgxFormWithArrayControls, OnFormUpdate } from './ngx-sub-form.types';
} from '../shared/ngx-sub-form-utils';
import { FormGroupOptions, NgxFormWithArrayControls, OnFormUpdate } from '../shared/ngx-sub-form.types';

type MapControlFunction<FormInterface, MapValue> = (
ctrl: TypedAbstractControl<any>,
Expand Down
11 changes: 0 additions & 11 deletions projects/ngx-sub-form/src/lib/ngx-sub-form-tokens.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, InjectionToken, Type } from '@angular/core';
import { InjectionToken, Type } from '@angular/core';
import {
AbstractControl,
ControlValueAccessor,
Expand All @@ -11,8 +11,7 @@ import {
} from '@angular/forms';
import { Observable, Subject, timer } from 'rxjs';
import { debounce, takeUntil } from 'rxjs/operators';
import { SUB_FORM_COMPONENT_TOKEN } from './ngx-sub-form-tokens';
import { NgxSubFormComponent } from './ngx-sub-form.component';
import { NgxSubFormComponent } from '../deprecated/ngx-sub-form.component';

export type Controls<T> = { [K in keyof T]-?: AbstractControl };

Expand Down Expand Up @@ -111,10 +110,6 @@ export function subformComponentProviders(
useExisting: component,
multi: true,
},
{
provide: SUB_FORM_COMPONENT_TOKEN,
useExisting: component,
},
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormControl, FormGroup, ValidationErrors } from '@angular/forms';
import { FormControl, ValidationErrors } from '@angular/forms';
import { Observable } from 'rxjs';
import { ArrayPropertyKey, ArrayPropertyValue, Controls, FormUpdate, TypedFormGroup } from './ngx-sub-form-utils';
import { ArrayPropertyKey, ArrayPropertyValue, FormUpdate, TypedFormGroup } from './ngx-sub-form-utils';

// @deprecated
export interface OnFormUpdate<FormInterface> {
Expand Down
12 changes: 6 additions & 6 deletions projects/ngx-sub-form/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Public API Surface of sub-form
*/

export * from './lib/ngx-sub-form-utils';
export * from './lib/ngx-sub-form.component';
export * from './lib/ngx-root-form.component';
export * from './lib/ngx-automatic-root-form.component';
export * from './lib/ngx-sub-form.types';
export * from './lib/ngx-sub-form.decorators';
export * from './lib/deprecated/ngx-automatic-root-form.component';
export * from './lib/deprecated/ngx-root-form.component';
export * from './lib/deprecated/ngx-sub-form.component';
export * from './lib/deprecated/ngx-sub-form.decorators';
export * from './lib/shared/ngx-sub-form-utils';
export * from './lib/shared/ngx-sub-form.types';
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { AssassinDroid, AssassinDroidWeapon, DroidType } from 'src/app/interfaces/droid.interface';
import { createForm, NgxSubForm } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';

export const ASSASSIN_DROID_WEAPON_TEXT: { [K in AssassinDroidWeapon]: string } = {
[AssassinDroidWeapon.SABER]: 'Saber',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, NgxSubForm } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { AstromechDroid, AstromechDroidShape, DroidType } from '../../../../../interfaces/droid.interface';

@NgxSubForm()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import {
AssassinDroid,
AstromechDroid,
Expand All @@ -9,8 +10,6 @@ import {
OneDroid,
ProtocolDroid,
} from 'src/app/interfaces/droid.interface';
import { createForm, NgxSubForm } from '../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';
import { UnreachableCase } from '../../../../shared/utils';

interface OneDroidForm {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { DroidType, MedicalDroid } from 'src/app/interfaces/droid.interface';
import { createForm, NgxSubForm } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';

@NgxSubForm()
@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { getObservableLifecycle } from 'ngx-observable-lifecycle';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, NgxSubForm } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { DroidType, Languages, ProtocolDroid } from '../../../../../interfaces/droid.interface';

@NgxSubForm()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, Input, Output } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { Subject } from 'rxjs';
import { ListingType, OneListing } from 'src/app/interfaces/listing.interface';
import { createForm, NgxSubForm } from '../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';
import { OneDroid } from '../../../interfaces/droid.interface';
import { OneVehicle } from '../../../interfaces/vehicle.interface';
import { UnreachableCase } from '../../../shared/utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, NgxSubForm } from '../../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { CrewMember } from '../../../../../../interfaces/crew-member.interface';

@NgxSubForm()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Component, forwardRef } from '@angular/core';
import { FormArray, FormControl, Validators } from '@angular/forms';
import { ArrayPropertyKey, ArrayPropertyValue, subformComponentProviders } from 'ngx-sub-form';
import { createForm, NgxSubForm } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { CrewMember } from '../../../../../interfaces/crew-member.interface';

interface CrewMembersForm {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { Spaceship, VehicleType } from 'src/app/interfaces/vehicle.interface';
import { createForm, NgxSubForm } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';

@NgxSubForm()
@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { Speeder, VehicleType } from 'src/app/interfaces/vehicle.interface';
import { createForm, NgxSubForm } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';

@NgxSubForm()
@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Component, forwardRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { subformComponentProviders } from 'ngx-sub-form';
import { createForm, FormType, NgxSubForm } from 'ngx-sub-form/new';
import { OneVehicle, Spaceship, Speeder, VehicleType } from 'src/app/interfaces/vehicle.interface';
import { UnreachableCase } from 'src/app/shared/utils';
import { createForm, NgxSubForm } from '../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form';
import { FormType } from '../../../../../../projects/ngx-sub-form/src/lib/new/ngx-sub-form.types';

export interface OneVehicleForm {
speeder: Speeder | null;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"lib": ["es2018", "dom"],
"paths": {
"ngx-sub-form": ["projects/ngx-sub-form/src/public_api"],
"ngx-sub-form/*": ["projects/ngx-sub-form/src/public_api"]
"ngx-sub-form/new": ["projects/ngx-sub-form/public_api.new"]
}
}
}

0 comments on commit 3db939b

Please sign in to comment.