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.5.2 to 0.6.0

6

dist/modeled-mobx.js

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

if (!model) {
throw new Error(`model() called without a value on property ${target}#${property}`);
throw new Error(`model() called without a value on property ${target?.constructor.name}#${property}. Perhaps it was not imported correctly?`);
}

@@ -113,2 +113,6 @@

function hydrateModel(model, attrs, parent) {
if (model == null) {
throw new Error(`unable to hydrate null/undefined Model`);
}
if (typeof model.hydrate === 'function') {

@@ -115,0 +119,0 @@ return recordParentOf(model.hydrate(attrs), parent);

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

if (!model) {
throw new Error(`model() called without a value on property ${target}#${property}`);
throw new Error(`model() called without a value on property ${target == null ? void 0 : target.constructor.name}#${property}. Perhaps it was not imported correctly?`);
}

@@ -113,2 +113,6 @@

function hydrateModel(model, attrs, parent) {
if (model == null) {
throw new Error(`unable to hydrate null/undefined Model`);
}
if (typeof model.hydrate === 'function') {

@@ -115,0 +119,0 @@ return recordParentOf(model.hydrate(attrs), parent);

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

if (!model) {
throw new Error(`model() called without a value on property ${target}#${property}`);
throw new Error(`model() called without a value on property ${target?.constructor.name}#${property}. Perhaps it was not imported correctly?`);
}

@@ -113,2 +113,6 @@

function hydrateModel(model, attrs, parent) {
if (model == null) {
throw new Error(`unable to hydrate null/undefined Model`);
}
if (typeof model.hydrate === 'function') {

@@ -115,0 +119,0 @@ return recordParentOf(model.hydrate(attrs), parent);

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

if (!model) {
throw new Error(`model() called without a value on property ${target}#${property}`);
throw new Error(`model() called without a value on property ${target?.constructor.name}#${property}. Perhaps it was not imported correctly?`);
}

@@ -116,2 +116,6 @@

function hydrateModel(model, attrs, parent) {
if (model == null) {
throw new Error(`unable to hydrate null/undefined Model`);
}
if (typeof model.hydrate === 'function') {

@@ -118,0 +122,0 @@ return recordParentOf(model.hydrate(attrs), parent);

2

package.json
{
"name": "modeled-mobx",
"version": "0.5.2",
"version": "0.6.0",
"description": "MobX powered classes with type-coercion and serialization/hydration",

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

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

class Item {
name = '' // all properties MUST be given values, see edge cases section below
name = ''
material = ''

@@ -41,3 +41,3 @@ get box() { return getParentOf<Box>(this) }

@observable serial: number = 0; // observable from mobx will be set by hydrate
// and initialized by modelize. It will not be serialized
// and initialized by modelize. It will not be serialized
@computed get volume() {

@@ -48,3 +48,3 @@ return this.width * this.height * this.depth;

@model(Item) items: Item[] = []; // note: this is an array of "item" models
@model(Item) defaultItem?: Item = undefined; // and this one is a single model
@model(Item) defaultItem?: Item; // and this one is a single model

@@ -72,36 +72,29 @@ constructor() {

```
## Edge cases
## Edge cases and limitations
#### properties must be assigned a value
When using Javascript, if a property is not initialized, Mobx will raise an exception: `Cannot apply 'observable' to '<property name>': Field not found`
When using Javascript decorators and uninitialized properties, Mobx may raise an exception: `Cannot apply 'observable' to '<property name>': Field not found`. This is caused by an incorrect babel configuration. More info: https://github.com/nathanstitt/modeled-mobx/issues/1
for instance:
#### there must be properties to decorate
An exception will be raised if modelize is called with no properties and none are decorated.
```js
class Item {
name
constructor() {
modelize(this, {
name: field,
})
}
class EmptyThing {
name = 'empty'
constructor() {
modelize(this);
}
}
```
Will trigger the exception, but this usage is fine:
```js
class Item {
name = ''
constructor() {
modelize(this, {
name: field,
})
}
}
new EmptyThing() // raises "[MobX] No annotations were passed to makeObservable, but no decorated members have been found either"
```
#### inheritance is tricky
This seems to be a limitation of ES6. If a field is present but not given a value, it will be "undefined", and MobX thinks that it's not present.
There have been multiple bugs worked around in attempting to inherit from a modelized base class. It now seems to be working but there may still be lingering bugs. Please open issues if you note any weirdness.

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