Skip to content

Commit

Permalink
6.7.0
Browse files Browse the repository at this point in the history
Also fixes some errors/unused code caught by typescript 2.6
  • Loading branch information
smithad15 committed Jan 21, 2018
1 parent 77a58de commit ddedc50
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 55 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# NOTE: For changelog information for v6.5.3 and above, please see the GitHub release notes.

# 6.5.1 - Support typescript unused checks

* https://github.com/angular-redux/form/pull/32
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@angular-redux/form",
"version": "6.6.0",
"version": "6.7.0",
"description": "Build Angular 2+ forms with Redux",
"dependencies": {
"immutable": "^3.8.1"
Expand Down
18 changes: 2 additions & 16 deletions source/connect-array/connect-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
OnInit,
} from '@angular/core';
import {
NG_VALUE_ACCESSOR,
AbstractControl,
FormArray,
FormArrayName,
Expand All @@ -22,7 +21,6 @@ import {
FormGroupDirective,
NgModelGroup,
ControlContainer,
ControlValueAccessor,
} from '@angular/forms';

import {
Expand All @@ -39,7 +37,7 @@ import {Unsubscribe} from 'redux';
import {ConnectBase} from '../connect';
import {FormStore} from '../form-store';
import {State} from '../state';
import {controlPath, selectValueAccessor} from '../shims';
import {controlPath} from '../shims';

export class ConnectArrayTemplate {
constructor(
Expand All @@ -61,15 +59,12 @@ export class ConnectArray extends ControlContainer implements OnInit {

private array = new FormArray([]);

private valueAccessor: ControlValueAccessor;

private key: string;

constructor(
@Optional() @Host() @SkipSelf() private parent: ControlContainer,
@Optional() @Self() @Inject(NG_VALIDATORS) private rawValidators: any[],
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private rawAsyncValidators: any[],
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: any[],
private connection: ConnectBase,
private templateRef: TemplateRef<any>,
private viewContainerRef: ViewContainerRef,
Expand All @@ -79,8 +74,6 @@ export class ConnectArray extends ControlContainer implements OnInit {

this.stateSubscription = this.store.subscribe(state => this.resetState(state));

this.valueAccessor = selectValueAccessor(<any> this, valueAccessors) || this.simpleAccessor();

this.registerInternals(this.array);
}

Expand Down Expand Up @@ -129,6 +122,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
this.viewContainerRef.clear();

this.formDirective.form.removeControl(this.key);
this.stateSubscription()
}

private resetState(state: any) {
Expand Down Expand Up @@ -277,12 +271,4 @@ export class ConnectArray extends ControlContainer implements OnInit {
`Cannot convert object of type ${typeof reference} / ${reference.toString()} to form element`);
}
}

private simpleAccessor() {
return {
writeValue: (value: any) => this.control.setValue(value),
registerOnChange() {},
registerOnTouched() {}
};
}
}
35 changes: 0 additions & 35 deletions source/shims.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
NgControl,
ControlContainer,
ControlValueAccessor,
DefaultValueAccessor,
CheckboxControlValueAccessor,
SelectControlValueAccessor,
SelectMultipleControlValueAccessor,
Expand All @@ -13,39 +11,6 @@ export function controlPath(name: string, parent: ControlContainer): string[] {
return [...(parent.path || []), name];
}

export function selectValueAccessor(
dir: NgControl, valueAccessors: ControlValueAccessor[]): ControlValueAccessor | null {
if (!valueAccessors) return null;

let defaultAccessor: ControlValueAccessor | null = null;
let builtinAccessor: ControlValueAccessor | null = null;
let customAccessor: ControlValueAccessor | null = null;
valueAccessors.forEach((v: ControlValueAccessor) => {
if (v.constructor === DefaultValueAccessor) {
defaultAccessor = v;
} else if (isBuiltInAccessor(v)) {
if (builtinAccessor) {
throw new Error(
`More than one built-in value accessor matches form control with ${dir}`);
}

builtinAccessor = v;
} else {
if (customAccessor) {
throw new Error(
`More than one custom value accessor matches form control with ${dir}`);
}
customAccessor = v;
}
});

if (customAccessor) return customAccessor;
if (builtinAccessor) return builtinAccessor;
if (defaultAccessor) return defaultAccessor;

throw new Error(`No valid value accessor for form control with, ${dir}`);
}

const BUILTIN_ACCESSORS = [
CheckboxControlValueAccessor,
SelectControlValueAccessor,
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3418,9 +3418,9 @@ type-is@~1.6.14:
media-typer "0.3.0"
mime-types "~2.1.13"

typescript@latest:
version "2.4.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.1.tgz#c3ccb16ddaa0b2314de031e7e6fee89e5ba346bc"
typescript@^2.4.1:
version "2.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"

uglify-js@^2.6, uglify-js@^2.7.5:
version "2.7.5"
Expand Down

0 comments on commit ddedc50

Please sign in to comment.