Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Draft of fix for ChainableAttributeSpec being assigned to SharedType …
…type attribute
  • Loading branch information
remaininlight committed Apr 29, 2019
commit daba19745321c4ea11e7ee993d83ef7b0f70d405
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/record/metatypes/any.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export declare class AnyType implements AttributeUpdatePipeline {
createPropertyDescriptor(): PropertyDescriptor | void;
value: any;
static defaultValue: any;
type: Function;
type: any;
initialize(name: string, options: TransactionOptions): void;
options: AttributeOptions;
doInit(value: any, record: AttributesContainer, options: TransactionOptions): any;
Expand Down
3 changes: 2 additions & 1 deletion lib/record/metatypes/shared.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Transactional, TransactionOptions } from '../../transactions';
import { AnyType } from './any';
import { AttributesContainer, ConstructorOptions } from '../updates';
import { ChainableAttributeSpec } from '../attrDef';
export declare class SharedType extends AnyType {
type: typeof Transactional;
type: typeof Transactional | ChainableAttributeSpec<Function>;
doInit(value: any, record: AttributesContainer, options: ConstructorOptions): any;
doUpdate(value: any, record: any, options: any, nested: any[]): boolean;
clone(value: Transactional, record: AttributesContainer): Transactional;
Expand Down
9 changes: 7 additions & 2 deletions lib/record/metatypes/shared.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/record/metatypes/shared.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/record/metatypes/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class AnyType implements AttributeUpdatePipeline {
// Used as global default value for the given metatype
static defaultValue : any;

type : Function
type : any

initialize( name : string, options : TransactionOptions ){}

Expand Down
14 changes: 11 additions & 3 deletions src/record/metatypes/shared.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { eventsApi } from '../../object-plus';
import { ItemsBehavior, Transactional, transactionApi, TransactionOptions } from '../../transactions';
import { AnyType } from './any';
import { type } from '../attrDef'
import { AttributesContainer, ConstructorOptions } from '../updates';
import { ChainableAttributeSpec } from '../attrDef';

Expand All @@ -17,9 +18,14 @@ const { on, off } = eventsApi,

const shareAndListen = ItemsBehavior.listen | ItemsBehavior.share;

function getType(input: any) {
return input.type.options ? input.type.options.type : input.type;
}

/** @private */
export class SharedType extends AnyType {
type : typeof Transactional
//type : ChainableAttributeSpec<Function>
type : typeof Transactional | ChainableAttributeSpec<Function>

doInit( value, record : AttributesContainer, options : ConstructorOptions ){
const v = options.clone ? this.clone( value, record ) : (
Expand Down Expand Up @@ -81,13 +87,15 @@ export class SharedType extends AnyType {

canBeUpdated( prev : Transactional, next : any, options : TransactionOptions ) : any {
// If an object already exists, and new value is of incompatible type, let object handle the update.
if( prev && next != null && !( next instanceof this.type ) ){
let type = getType(this);
if( prev && next != null && !( next instanceof type ) ){
return next;
}
}

convert( next : any, prev : any, record : AttributesContainer, options : TransactionOptions ) : Transactional {
if( next == null || next instanceof this.type ) return next;
let type = getType(this);
if( next == null || next instanceof type ) return next;

// Convert type using implicitly created transactional object.
const implicitObject = new ( this.type as any )( next, options, shareAndListen );
Expand Down