Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

modeled-mobx

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modeled-mobx - npm Package Compare versions

Comparing version 0.3.6 to 0.4.0

2

dist/index.d.ts
export { modelize } from './modelize';
export { serialize, hydrate } from './serialize-hydrate';
export { serialize, hydrateModel, hydrateInstance } from './serialize-hydrate';
export { getParentOf } from './inverse';
export { field, model } from './schema';

@@ -95,3 +95,3 @@ var mobx = require('mobx');

if (Array.isArray(instance[prop])) {
const values = Array.isArray(attrs[prop]) ? attrs[prop].map(childProps => hydrate(options.model, childProps, instance)) : [hydrate(options.model, attrs[prop], instance)];
const values = Array.isArray(attrs[prop]) ? attrs[prop].map(childProps => hydrateModel(options.model, childProps, instance)) : [hydrateModel(options.model, attrs[prop], instance)];
instance[prop].splice(0, instance[prop].length, ...values);

@@ -102,3 +102,3 @@ } else {

} else {
instance[prop] = hydrate(options.model, attrs[prop], instance);
instance[prop] = hydrateModel(options.model, attrs[prop], instance);
}

@@ -111,3 +111,3 @@ }

function hydrate(model, attrs, parent) {
function hydrateModel(model, attrs, parent) {
if (typeof model.hydrate === 'function') {

@@ -118,2 +118,5 @@ return recordParentOf(model.hydrate(attrs), parent);

const instance = new model(attrs);
return hydrateInstance(instance, attrs, parent);
}
function hydrateInstance(instance, attrs, parent) {
recordParentOf(instance, parent);

@@ -165,3 +168,3 @@ const schema = getSchema(instance);

if (!(change.newValue instanceof desiredModel)) {
change.newValue = hydrate(desiredModel, change.newValue);
change.newValue = hydrateModel(desiredModel, change.newValue);
}

@@ -189,3 +192,3 @@

} else {
child = hydrate(desiredModel, attrs);
child = hydrateModel(desiredModel, attrs);
}

@@ -252,3 +255,4 @@

exports.getParentOf = getParentOf;
exports.hydrate = hydrate;
exports.hydrateInstance = hydrateInstance;
exports.hydrateModel = hydrateModel;
exports.model = model;

@@ -255,0 +259,0 @@ exports.modelize = modelize;

@@ -95,3 +95,3 @@ import { observable, intercept, isObservableArray, makeObservable } from 'mobx';

if (Array.isArray(instance[prop])) {
const values = Array.isArray(attrs[prop]) ? attrs[prop].map(childProps => hydrate(options.model, childProps, instance)) : [hydrate(options.model, attrs[prop], instance)];
const values = Array.isArray(attrs[prop]) ? attrs[prop].map(childProps => hydrateModel(options.model, childProps, instance)) : [hydrateModel(options.model, attrs[prop], instance)];
instance[prop].splice(0, instance[prop].length, ...values);

@@ -102,3 +102,3 @@ } else {

} else {
instance[prop] = hydrate(options.model, attrs[prop], instance);
instance[prop] = hydrateModel(options.model, attrs[prop], instance);
}

@@ -111,3 +111,3 @@ }

function hydrate(model, attrs, parent) {
function hydrateModel(model, attrs, parent) {
if (typeof model.hydrate === 'function') {

@@ -118,2 +118,5 @@ return recordParentOf(model.hydrate(attrs), parent);

const instance = new model(attrs);
return hydrateInstance(instance, attrs, parent);
}
function hydrateInstance(instance, attrs, parent) {
recordParentOf(instance, parent);

@@ -165,3 +168,3 @@ const schema = getSchema(instance);

if (!(change.newValue instanceof desiredModel)) {
change.newValue = hydrate(desiredModel, change.newValue);
change.newValue = hydrateModel(desiredModel, change.newValue);
}

@@ -189,3 +192,3 @@

} else {
child = hydrate(desiredModel, attrs);
child = hydrateModel(desiredModel, attrs);
}

@@ -250,3 +253,3 @@

export { field, getParentOf, hydrate, model, modelize, serialize };
export { field, getParentOf, hydrateInstance, hydrateModel, model, modelize, serialize };
//# sourceMappingURL=modeled-mobx.modern.js.map

@@ -95,3 +95,3 @@ import { observable, intercept, isObservableArray, makeObservable } from 'mobx';

if (Array.isArray(instance[prop])) {
const values = Array.isArray(attrs[prop]) ? attrs[prop].map(childProps => hydrate(options.model, childProps, instance)) : [hydrate(options.model, attrs[prop], instance)];
const values = Array.isArray(attrs[prop]) ? attrs[prop].map(childProps => hydrateModel(options.model, childProps, instance)) : [hydrateModel(options.model, attrs[prop], instance)];
instance[prop].splice(0, instance[prop].length, ...values);

@@ -102,3 +102,3 @@ } else {

} else {
instance[prop] = hydrate(options.model, attrs[prop], instance);
instance[prop] = hydrateModel(options.model, attrs[prop], instance);
}

@@ -111,3 +111,3 @@ }

function hydrate(model, attrs, parent) {
function hydrateModel(model, attrs, parent) {
if (typeof model.hydrate === 'function') {

@@ -118,2 +118,5 @@ return recordParentOf(model.hydrate(attrs), parent);

const instance = new model(attrs);
return hydrateInstance(instance, attrs, parent);
}
function hydrateInstance(instance, attrs, parent) {
recordParentOf(instance, parent);

@@ -165,3 +168,3 @@ const schema = getSchema(instance);

if (!(change.newValue instanceof desiredModel)) {
change.newValue = hydrate(desiredModel, change.newValue);
change.newValue = hydrateModel(desiredModel, change.newValue);
}

@@ -189,3 +192,3 @@

} else {
child = hydrate(desiredModel, attrs);
child = hydrateModel(desiredModel, attrs);
}

@@ -250,3 +253,3 @@

export { field, getParentOf, hydrate, model, modelize, serialize };
export { field, getParentOf, hydrateInstance, hydrateModel, model, modelize, serialize };
//# sourceMappingURL=modeled-mobx.module.js.map

@@ -98,3 +98,3 @@ (function (global, factory) {

if (Array.isArray(instance[prop])) {
const values = Array.isArray(attrs[prop]) ? attrs[prop].map(childProps => hydrate(options.model, childProps, instance)) : [hydrate(options.model, attrs[prop], instance)];
const values = Array.isArray(attrs[prop]) ? attrs[prop].map(childProps => hydrateModel(options.model, childProps, instance)) : [hydrateModel(options.model, attrs[prop], instance)];
instance[prop].splice(0, instance[prop].length, ...values);

@@ -105,3 +105,3 @@ } else {

} else {
instance[prop] = hydrate(options.model, attrs[prop], instance);
instance[prop] = hydrateModel(options.model, attrs[prop], instance);
}

@@ -114,3 +114,3 @@ }

function hydrate(model, attrs, parent) {
function hydrateModel(model, attrs, parent) {
if (typeof model.hydrate === 'function') {

@@ -121,2 +121,5 @@ return recordParentOf(model.hydrate(attrs), parent);

const instance = new model(attrs);
return hydrateInstance(instance, attrs, parent);
}
function hydrateInstance(instance, attrs, parent) {
recordParentOf(instance, parent);

@@ -168,3 +171,3 @@ const schema = getSchema(instance);

if (!(change.newValue instanceof desiredModel)) {
change.newValue = hydrate(desiredModel, change.newValue);
change.newValue = hydrateModel(desiredModel, change.newValue);
}

@@ -192,3 +195,3 @@

} else {
child = hydrate(desiredModel, attrs);
child = hydrateModel(desiredModel, attrs);
}

@@ -255,3 +258,4 @@

exports.getParentOf = getParentOf;
exports.hydrate = hydrate;
exports.hydrateInstance = hydrateInstance;
exports.hydrateModel = hydrateModel;
exports.model = model;

@@ -258,0 +262,0 @@ exports.modelize = modelize;

@@ -1,3 +0,4 @@

import { JSON, Model } from './types';
export declare function hydrate<T extends Model>(model: T, attrs: any, parent?: any): InstanceType<T>;
import { JSON, Model, ModelInstance } from './types';
export declare function hydrateModel<T extends Model>(model: T, attrs: any, parent?: any): InstanceType<T>;
export declare function hydrateInstance<T extends ModelInstance>(instance: T, attrs: any, parent?: any): T;
export declare function serialize<T extends object>(model: T): JSON;

@@ -10,3 +10,5 @@ import { AnnotationsMap } from 'mobx';

}
export declare type ModelInstance = InstanceType<Model>;
export interface ModelInstance extends InstanceType<Model> {
hydrate?(attrs: any): void;
}
export interface ModelOption extends Function {

@@ -13,0 +15,0 @@ model?: Model;

{
"name": "modeled-mobx",
"version": "0.3.6",
"version": "0.4.0",
"description": "MobX powered classes with type-coercion and serialization/hydration",

@@ -5,0 +5,0 @@ "author": "nathanstitt",

@@ -17,3 +17,3 @@ # Create model relationships with mobx

```typescript
import { modelize, field, model, hydrate, serialize, getParentOf } from 'modeled-mobx'
import { modelize, field, model, hydrateModel, serialize, getParentOf } from 'modeled-mobx'
import { observable, computed } from 'mobx'

@@ -55,3 +55,3 @@

const box = hydrate(Box, {
const box = hydrateModel(Box, {
width: 10, height: 10, depth: 10, serial: 1234,

@@ -58,0 +58,0 @@ items: [{ name: 'Box #1' }, { name: 'Box #2' }],

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc