Comparing version 0.2.0-beta.28 to 0.2.0-beta.29
@@ -17,7 +17,3 @@ "use strict"; | ||
? function (defaultValue) { return childBuilder.build(defaultValue); } | ||
: function (defaultValue) { | ||
return new ref_1.ModelRef(undefined, defaultValue, { | ||
owner: _this, | ||
}); | ||
}; | ||
: function (defaultValue) { return new ref_1.ModelRef(undefined, defaultValue, _this); }; | ||
var children = _this.defaultValue.map(_this.childFactory); | ||
@@ -24,0 +20,0 @@ _this.children$ = new rxjs_1.BehaviorSubject(children); |
@@ -10,2 +10,3 @@ import { BehaviorSubject, Subject, Observable } from 'rxjs'; | ||
declare class FormModel<Children extends Record<string, BasicModel<any>> = Record<string, BasicModel<any>>> extends FieldSetModel<Children> { | ||
readonly children: Children; | ||
/** | ||
@@ -19,2 +20,3 @@ * @internal | ||
readonly change$: Subject<void>; | ||
constructor(children: Children); | ||
/** @internal */ | ||
@@ -21,0 +23,0 @@ addWorkingValidator(v: Observable<unknown>): void; |
@@ -15,4 +15,5 @@ "use strict"; | ||
tslib_1.__extends(FormModel, _super); | ||
function FormModel() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
function FormModel(children) { | ||
var _this = _super.call(this, children) || this; | ||
_this.children = children; | ||
/** @internal */ | ||
@@ -22,2 +23,3 @@ _this.workingValidators = new Set(); | ||
_this.change$ = new rxjs_1.Subject(); | ||
_this.form = _this; | ||
return _this; | ||
@@ -24,0 +26,0 @@ } |
import { BasicModel, IModel } from './basic'; | ||
import { ValidateOption, IMaybeError } from '../validate'; | ||
interface IModelRefContext<Parent> { | ||
owner: Parent; | ||
} | ||
declare const REF: unique symbol; | ||
declare class ModelRef<Value, Parent, Model extends BasicModel<Value> = BasicModel<Value>> implements IModel<Value | null> { | ||
declare class ModelRef<Value, Parent extends BasicModel<any>, Model extends BasicModel<Value> = BasicModel<Value>> implements IModel<Value | null> { | ||
private current; | ||
initialValue: Value | undefined; | ||
private ctx; | ||
private owner; | ||
/** | ||
@@ -22,6 +19,6 @@ * @internal | ||
*/ | ||
constructor(current: Model | undefined, initialValue: Value | undefined, ctx: IModelRefContext<Parent>); | ||
getModel(): Model | undefined; | ||
setModel(model: Model | undefined): void; | ||
getParent(): Parent; | ||
constructor(current: Model | undefined | null, initialValue: Value | undefined, owner: Parent | null); | ||
getModel(): Model | null | undefined; | ||
setModel(model: Model | undefined | null): void; | ||
getParent(): Parent | null; | ||
dirty(): boolean; | ||
@@ -39,4 +36,4 @@ touched(): boolean; | ||
} | ||
declare function isModelRef<T, P, M extends BasicModel<T> = BasicModel<T>>(maybeModelRef: any): maybeModelRef is ModelRef<T, P, M>; | ||
export { IModelRefContext, ModelRef, isModelRef }; | ||
declare function isModelRef<T, P extends BasicModel<any>, M extends BasicModel<T> = BasicModel<T>>(maybeModelRef: any): maybeModelRef is ModelRef<T, P, M>; | ||
export { ModelRef, isModelRef }; | ||
//# sourceMappingURL=ref.d.ts.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
*/ | ||
function ModelRef(current, initialValue, ctx) { | ||
function ModelRef(current, initialValue, owner) { | ||
if (current === void 0) { current = undefined; } | ||
@@ -15,3 +15,3 @@ if (initialValue === void 0) { initialValue = undefined; } | ||
this.initialValue = initialValue; | ||
this.ctx = ctx; | ||
this.owner = owner; | ||
/** | ||
@@ -26,6 +26,14 @@ * @internal | ||
ModelRef.prototype.setModel = function (model) { | ||
if (this.current) { | ||
this.current.form = null; | ||
this.current.owner = null; | ||
} | ||
this.current = model; | ||
if (model) { | ||
model.form = this.owner && this.owner.form; | ||
model.owner = this; | ||
} | ||
}; | ||
ModelRef.prototype.getParent = function () { | ||
return this.ctx.owner; | ||
return this.owner; | ||
}; | ||
@@ -32,0 +40,0 @@ ModelRef.prototype.dirty = function () { |
@@ -52,2 +52,4 @@ "use strict"; | ||
FieldSetModel.prototype.registerChild = function (name, model) { | ||
model.form = this.form; | ||
model.owner = this; | ||
this.children[name] = model; | ||
@@ -59,2 +61,4 @@ this.childRegister$.next(name); | ||
delete this.children[name]; | ||
model.form = null; | ||
model.owner = null; | ||
this.childRemove$.next(name); | ||
@@ -61,0 +65,0 @@ return model; |
@@ -15,7 +15,3 @@ import * as tslib_1 from "tslib"; | ||
? function (defaultValue) { return childBuilder.build(defaultValue); } | ||
: function (defaultValue) { | ||
return new ModelRef(undefined, defaultValue, { | ||
owner: _this, | ||
}); | ||
}; | ||
: function (defaultValue) { return new ModelRef(undefined, defaultValue, _this); }; | ||
var children = _this.defaultValue.map(_this.childFactory); | ||
@@ -22,0 +18,0 @@ _this.children$ = new BehaviorSubject(children); |
@@ -10,2 +10,3 @@ import { BehaviorSubject, Subject, Observable } from 'rxjs'; | ||
declare class FormModel<Children extends Record<string, BasicModel<any>> = Record<string, BasicModel<any>>> extends FieldSetModel<Children> { | ||
readonly children: Children; | ||
/** | ||
@@ -19,2 +20,3 @@ * @internal | ||
readonly change$: Subject<void>; | ||
constructor(children: Children); | ||
/** @internal */ | ||
@@ -21,0 +23,0 @@ addWorkingValidator(v: Observable<unknown>): void; |
@@ -12,4 +12,5 @@ import * as tslib_1 from "tslib"; | ||
tslib_1.__extends(FormModel, _super); | ||
function FormModel() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
function FormModel(children) { | ||
var _this = _super.call(this, children) || this; | ||
_this.children = children; | ||
/** @internal */ | ||
@@ -19,2 +20,3 @@ _this.workingValidators = new Set(); | ||
_this.change$ = new Subject(); | ||
_this.form = _this; | ||
return _this; | ||
@@ -21,0 +23,0 @@ } |
import { BasicModel, IModel } from './basic'; | ||
import { ValidateOption, IMaybeError } from '../validate'; | ||
interface IModelRefContext<Parent> { | ||
owner: Parent; | ||
} | ||
declare const REF: unique symbol; | ||
declare class ModelRef<Value, Parent, Model extends BasicModel<Value> = BasicModel<Value>> implements IModel<Value | null> { | ||
declare class ModelRef<Value, Parent extends BasicModel<any>, Model extends BasicModel<Value> = BasicModel<Value>> implements IModel<Value | null> { | ||
private current; | ||
initialValue: Value | undefined; | ||
private ctx; | ||
private owner; | ||
/** | ||
@@ -22,6 +19,6 @@ * @internal | ||
*/ | ||
constructor(current: Model | undefined, initialValue: Value | undefined, ctx: IModelRefContext<Parent>); | ||
getModel(): Model | undefined; | ||
setModel(model: Model | undefined): void; | ||
getParent(): Parent; | ||
constructor(current: Model | undefined | null, initialValue: Value | undefined, owner: Parent | null); | ||
getModel(): Model | null | undefined; | ||
setModel(model: Model | undefined | null): void; | ||
getParent(): Parent | null; | ||
dirty(): boolean; | ||
@@ -39,4 +36,4 @@ touched(): boolean; | ||
} | ||
declare function isModelRef<T, P, M extends BasicModel<T> = BasicModel<T>>(maybeModelRef: any): maybeModelRef is ModelRef<T, P, M>; | ||
export { IModelRefContext, ModelRef, isModelRef }; | ||
declare function isModelRef<T, P extends BasicModel<any>, M extends BasicModel<T> = BasicModel<T>>(maybeModelRef: any): maybeModelRef is ModelRef<T, P, M>; | ||
export { ModelRef, isModelRef }; | ||
//# sourceMappingURL=ref.d.ts.map |
@@ -7,3 +7,3 @@ import { ValidateOption } from '../validate'; | ||
*/ | ||
function ModelRef(current, initialValue, ctx) { | ||
function ModelRef(current, initialValue, owner) { | ||
if (current === void 0) { current = undefined; } | ||
@@ -13,3 +13,3 @@ if (initialValue === void 0) { initialValue = undefined; } | ||
this.initialValue = initialValue; | ||
this.ctx = ctx; | ||
this.owner = owner; | ||
/** | ||
@@ -24,6 +24,14 @@ * @internal | ||
ModelRef.prototype.setModel = function (model) { | ||
if (this.current) { | ||
this.current.form = null; | ||
this.current.owner = null; | ||
} | ||
this.current = model; | ||
if (model) { | ||
model.form = this.owner && this.owner.form; | ||
model.owner = this; | ||
} | ||
}; | ||
ModelRef.prototype.getParent = function () { | ||
return this.ctx.owner; | ||
return this.owner; | ||
}; | ||
@@ -30,0 +38,0 @@ ModelRef.prototype.dirty = function () { |
@@ -50,2 +50,4 @@ import * as tslib_1 from "tslib"; | ||
FieldSetModel.prototype.registerChild = function (name, model) { | ||
model.form = this.form; | ||
model.owner = this; | ||
this.children[name] = model; | ||
@@ -57,2 +59,4 @@ this.childRegister$.next(name); | ||
delete this.children[name]; | ||
model.form = null; | ||
model.owner = null; | ||
this.childRemove$.next(name); | ||
@@ -59,0 +63,0 @@ return model; |
{ | ||
"name": "formulr", | ||
"version": "0.2.0-beta.28", | ||
"version": "0.2.0-beta.29", | ||
"description": "Form toolkit for React", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -28,6 +28,3 @@ import { BehaviorSubject } from 'rxjs'; | ||
? (defaultValue: Item) => childBuilder.build(defaultValue) | ||
: (defaultValue: Item) => | ||
new ModelRef<Item, FieldArrayModel<Item, Child>, Child>(undefined, defaultValue, { | ||
owner: this, | ||
}); | ||
: (defaultValue: Item) => new ModelRef<Item, FieldArrayModel<Item, Child>, Child>(undefined, defaultValue, this); | ||
const children = this.defaultValue.map(this.childFactory); | ||
@@ -34,0 +31,0 @@ this.children$ = new BehaviorSubject(children); |
@@ -25,2 +25,7 @@ import { BehaviorSubject, Subject, Observable } from 'rxjs'; | ||
constructor(public readonly children: Children) { | ||
super(children); | ||
this.form = this; | ||
} | ||
/** @internal */ | ||
@@ -27,0 +32,0 @@ addWorkingValidator(v: Observable<unknown>) { |
import { BasicModel, IModel } from './basic'; | ||
import { ValidateOption, IMaybeError } from '../validate'; | ||
interface IModelRefContext<Parent> { | ||
owner: Parent; | ||
} | ||
const REF = Symbol('ref'); | ||
class ModelRef<Value, Parent, Model extends BasicModel<Value> = BasicModel<Value>> implements IModel<Value | null> { | ||
class ModelRef<Value, Parent extends BasicModel<any>, Model extends BasicModel<Value> = BasicModel<Value>> | ||
implements IModel<Value | null> { | ||
/** | ||
@@ -25,5 +22,5 @@ * @internal | ||
constructor( | ||
private current: Model | undefined = undefined, | ||
private current: Model | undefined | null = undefined, | ||
public initialValue: Value | undefined = undefined, | ||
private ctx: IModelRefContext<Parent>, | ||
private owner: Parent | null, | ||
) {} | ||
@@ -35,8 +32,16 @@ | ||
setModel(model: Model | undefined) { | ||
setModel(model: Model | undefined | null) { | ||
if (this.current) { | ||
this.current.form = null; | ||
this.current.owner = null; | ||
} | ||
this.current = model; | ||
if (model) { | ||
model.form = this.owner && this.owner.form; | ||
model.owner = this; | ||
} | ||
} | ||
getParent() { | ||
return this.ctx.owner; | ||
return this.owner; | ||
} | ||
@@ -129,3 +134,3 @@ | ||
function isModelRef<T, P, M extends BasicModel<T> = BasicModel<T>>( | ||
function isModelRef<T, P extends BasicModel<any>, M extends BasicModel<T> = BasicModel<T>>( | ||
maybeModelRef: any, | ||
@@ -136,2 +141,2 @@ ): maybeModelRef is ModelRef<T, P, M> { | ||
export { IModelRefContext, ModelRef, isModelRef }; | ||
export { ModelRef, isModelRef }; |
@@ -65,2 +65,4 @@ import { Subject } from 'rxjs'; | ||
registerChild(name: string, model: BasicModel<unknown>) { | ||
model.form = this.form; | ||
model.owner = this; | ||
this.children[name] = model; | ||
@@ -73,2 +75,4 @@ this.childRegister$.next(name); | ||
delete this.children[name]; | ||
model.form = null; | ||
model.owner = null; | ||
this.childRemove$.next(name); | ||
@@ -75,0 +79,0 @@ return model; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
332040
5463