modeled-mobx
Advanced tools
Comparing version 0.5.0 to 0.5.1
import { Model, ModelInstance } from './types'; | ||
import { ModelSchema } from './schema'; | ||
export declare function configureHasOne(parent: ModelInstance, property: string, desiredModel: Model): void; | ||
export declare function configureHasMany(parent: ModelInstance, property: string, desiredModel: Model): void; | ||
export declare function addInterceptors(model: ModelInstance, schema: ModelSchema): void; |
@@ -37,2 +37,3 @@ var mobx = require('mobx'); | ||
if (property) { | ||
mobx.observable(model, property); | ||
decorate(target, property, field); | ||
@@ -209,2 +210,13 @@ } else { | ||
} | ||
function addInterceptors(model, schema) { | ||
schema.properties.forEach((options, property) => { | ||
if (options && options.type == 'model' && mobx.isObservableProp(model, property)) { | ||
if (Array.isArray(model[property])) { | ||
configureHasMany(model, property, options.model); | ||
} else { | ||
configureHasOne(model, property, options.model); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -214,3 +226,3 @@ function modelize(model, properties, options) { | ||
if (!properties && !decoratedSchema || properties && properties.decorateOnly) { | ||
if (!properties && !decoratedSchema) { | ||
mobx.makeObservable(model); | ||
@@ -223,10 +235,13 @@ return; | ||
if (properties) { | ||
Object.keys(properties).forEach(property => { | ||
if (!schema.recordProperty(property, properties[property])) { | ||
mobxAnnotations[property] = properties[property]; | ||
} | ||
}); | ||
if (!properties) { | ||
mobx.makeObservable(model); | ||
addInterceptors(model, schema); | ||
return; | ||
} | ||
Object.keys(properties).forEach(property => { | ||
if (!schema.recordProperty(property, properties[property])) { | ||
mobxAnnotations[property] = properties[property]; | ||
} | ||
}); | ||
Array.from(schema.properties.keys()).forEach(property => { | ||
@@ -244,11 +259,3 @@ if (Object.prototype.hasOwnProperty.call(model, property) && !mobx.isObservableProp(model, property)) { | ||
schema.properties.forEach((options, property) => { | ||
if (options && options.type == 'model' && mobx.isObservableProp(model, property)) { | ||
if (Array.isArray(model[property])) { | ||
configureHasMany(model, property, options.model); | ||
} else { | ||
configureHasOne(model, property, options.model); | ||
} | ||
} | ||
}); | ||
addInterceptors(model, schema); | ||
} | ||
@@ -255,0 +262,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { observable, intercept, isObservableArray, makeObservable, isObservableProp } from 'mobx'; | ||
import { observable, isObservableProp, intercept, isObservableArray, makeObservable } from 'mobx'; | ||
@@ -37,2 +37,3 @@ const $schema = Symbol('modeled mobx schema'); | ||
if (property) { | ||
observable(model, property); | ||
decorate(target, property, field); | ||
@@ -209,2 +210,13 @@ } else { | ||
} | ||
function addInterceptors(model, schema) { | ||
schema.properties.forEach((options, property) => { | ||
if (options && options.type == 'model' && isObservableProp(model, property)) { | ||
if (Array.isArray(model[property])) { | ||
configureHasMany(model, property, options.model); | ||
} else { | ||
configureHasOne(model, property, options.model); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -214,3 +226,3 @@ function modelize(model, properties, options) { | ||
if (!properties && !decoratedSchema || properties && properties.decorateOnly) { | ||
if (!properties && !decoratedSchema) { | ||
makeObservable(model); | ||
@@ -223,10 +235,13 @@ return; | ||
if (properties) { | ||
Object.keys(properties).forEach(property => { | ||
if (!schema.recordProperty(property, properties[property])) { | ||
mobxAnnotations[property] = properties[property]; | ||
} | ||
}); | ||
if (!properties) { | ||
makeObservable(model); | ||
addInterceptors(model, schema); | ||
return; | ||
} | ||
Object.keys(properties).forEach(property => { | ||
if (!schema.recordProperty(property, properties[property])) { | ||
mobxAnnotations[property] = properties[property]; | ||
} | ||
}); | ||
Array.from(schema.properties.keys()).forEach(property => { | ||
@@ -244,11 +259,3 @@ if (Object.prototype.hasOwnProperty.call(model, property) && !isObservableProp(model, property)) { | ||
schema.properties.forEach((options, property) => { | ||
if (options && options.type == 'model' && isObservableProp(model, property)) { | ||
if (Array.isArray(model[property])) { | ||
configureHasMany(model, property, options.model); | ||
} else { | ||
configureHasOne(model, property, options.model); | ||
} | ||
} | ||
}); | ||
addInterceptors(model, schema); | ||
} | ||
@@ -255,0 +262,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { observable, intercept, isObservableArray, makeObservable, isObservableProp } from 'mobx'; | ||
import { observable, isObservableProp, intercept, isObservableArray, makeObservable } from 'mobx'; | ||
@@ -37,2 +37,3 @@ const $schema = Symbol('modeled mobx schema'); | ||
if (property) { | ||
observable(model, property); | ||
decorate(target, property, field); | ||
@@ -209,2 +210,13 @@ } else { | ||
} | ||
function addInterceptors(model, schema) { | ||
schema.properties.forEach((options, property) => { | ||
if (options && options.type == 'model' && isObservableProp(model, property)) { | ||
if (Array.isArray(model[property])) { | ||
configureHasMany(model, property, options.model); | ||
} else { | ||
configureHasOne(model, property, options.model); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -214,3 +226,3 @@ function modelize(model, properties, options) { | ||
if (!properties && !decoratedSchema || properties && properties.decorateOnly) { | ||
if (!properties && !decoratedSchema) { | ||
makeObservable(model); | ||
@@ -223,10 +235,13 @@ return; | ||
if (properties) { | ||
Object.keys(properties).forEach(property => { | ||
if (!schema.recordProperty(property, properties[property])) { | ||
mobxAnnotations[property] = properties[property]; | ||
} | ||
}); | ||
if (!properties) { | ||
makeObservable(model); | ||
addInterceptors(model, schema); | ||
return; | ||
} | ||
Object.keys(properties).forEach(property => { | ||
if (!schema.recordProperty(property, properties[property])) { | ||
mobxAnnotations[property] = properties[property]; | ||
} | ||
}); | ||
Array.from(schema.properties.keys()).forEach(property => { | ||
@@ -244,11 +259,3 @@ if (Object.prototype.hasOwnProperty.call(model, property) && !isObservableProp(model, property)) { | ||
schema.properties.forEach((options, property) => { | ||
if (options && options.type == 'model' && isObservableProp(model, property)) { | ||
if (Array.isArray(model[property])) { | ||
configureHasMany(model, property, options.model); | ||
} else { | ||
configureHasOne(model, property, options.model); | ||
} | ||
} | ||
}); | ||
addInterceptors(model, schema); | ||
} | ||
@@ -255,0 +262,0 @@ |
@@ -40,2 +40,3 @@ (function (global, factory) { | ||
if (property) { | ||
mobx.observable(model, property); | ||
decorate(target, property, field); | ||
@@ -212,2 +213,13 @@ } else { | ||
} | ||
function addInterceptors(model, schema) { | ||
schema.properties.forEach((options, property) => { | ||
if (options && options.type == 'model' && mobx.isObservableProp(model, property)) { | ||
if (Array.isArray(model[property])) { | ||
configureHasMany(model, property, options.model); | ||
} else { | ||
configureHasOne(model, property, options.model); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -217,3 +229,3 @@ function modelize(model, properties, options) { | ||
if (!properties && !decoratedSchema || properties && properties.decorateOnly) { | ||
if (!properties && !decoratedSchema) { | ||
mobx.makeObservable(model); | ||
@@ -226,10 +238,13 @@ return; | ||
if (properties) { | ||
Object.keys(properties).forEach(property => { | ||
if (!schema.recordProperty(property, properties[property])) { | ||
mobxAnnotations[property] = properties[property]; | ||
} | ||
}); | ||
if (!properties) { | ||
mobx.makeObservable(model); | ||
addInterceptors(model, schema); | ||
return; | ||
} | ||
Object.keys(properties).forEach(property => { | ||
if (!schema.recordProperty(property, properties[property])) { | ||
mobxAnnotations[property] = properties[property]; | ||
} | ||
}); | ||
Array.from(schema.properties.keys()).forEach(property => { | ||
@@ -247,11 +262,3 @@ if (Object.prototype.hasOwnProperty.call(model, property) && !mobx.isObservableProp(model, property)) { | ||
schema.properties.forEach((options, property) => { | ||
if (options && options.type == 'model' && mobx.isObservableProp(model, property)) { | ||
if (Array.isArray(model[property])) { | ||
configureHasMany(model, property, options.model); | ||
} else { | ||
configureHasOne(model, property, options.model); | ||
} | ||
} | ||
}); | ||
addInterceptors(model, schema); | ||
} | ||
@@ -258,0 +265,0 @@ |
@@ -6,7 +6,4 @@ import { CreateObservableOptions } from "mobx"; | ||
}; | ||
declare type DecorateOnly = { | ||
decorateOnly: true; | ||
}; | ||
export declare function modelize(model: ModelInstance, properties: DecorateOnly): void; | ||
export declare function modelize(model: ModelInstance, properties?: ModelizeProperties<ModelInstance>, options?: CreateObservableOptions): void; | ||
export declare function modelize(model: ModelInstance): void; | ||
export declare function modelize(model: ModelInstance, properties: ModelizeProperties<ModelInstance>, options?: CreateObservableOptions): void; | ||
export {}; |
{ | ||
"name": "modeled-mobx", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "MobX powered classes with type-coercion and serialization/hydration", | ||
@@ -5,0 +5,0 @@ "author": "nathanstitt", |
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
104298
964