Skip to content

Commit

Permalink
0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceK33z committed Apr 18, 2017
1 parent 12f70aa commit ca168fa
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
35 changes: 28 additions & 7 deletions dist/mobx-spine.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var _descriptor$1;
var _descriptor2$1;
var _descriptor3;
var _descriptor4;
var _class2$1;
var _temp$1;

function _initDefineProp$1(target, property, descriptor, context) {
if (!descriptor) return;
Expand Down Expand Up @@ -87,16 +89,21 @@ function _applyDecoratedDescriptor$1(

const AVAILABLE_CONST_OPTIONS = ['relations', 'limit'];

let Store = ((_class$1 = class Store {
// Holds the fetch parameters
let Store = ((_class$1 = ((_temp$1 = _class2$1 = class Store {
get isLoading() {
return this.__pendingRequestCount > 0;
}

// Holds the fetch parameters
get length() {
return this.models.length;
}

set backendResourceName(v) {
throw new Error(
'`backendResourceName` should be a static property on the store.'
);
}

constructor(options = {}) {
_initDefineProp$1(this, 'models', _descriptor$1, this);

Expand Down Expand Up @@ -373,7 +380,8 @@ let Store = ((_class$1 = class Store {
}
return this.models[index];
}
}), ((_descriptor$1 = _applyDecoratedDescriptor$1(
}), (_class2$1.backendResourceName =
''), _temp$1)), ((_descriptor$1 = _applyDecoratedDescriptor$1(
_class$1.prototype,
'models',
[observable],
Expand Down Expand Up @@ -574,6 +582,8 @@ function generateNegativeId() {

let Model = ((_class = ((_temp = _class2 = class Model {
// Holds activated - nested - relations (e.g. `['animal', 'animal.breed']`)

// How the model is known at the backend. This is useful when the model is in a relation that has a different name.
get url() {
const id = this[this.constructor.primaryKey];
return `${this.urlRoot}${id ? `${id}/` : ''}`;
Expand All @@ -597,6 +607,12 @@ let Model = ((_class = ((_temp = _class2 = class Model {
);
}

set backendResourceName(v) {
throw new Error(
'`backendResourceName` should be a static property on the model.'
);
}

casts() {
return {};
}
Expand Down Expand Up @@ -723,7 +739,12 @@ let Model = ((_class = ((_temp = _class2 = class Model {
data[relBackendName] = myNewId;
}
const relBackendData = rel.toBackendAll(myNewId);
relations[relBackendName] = relBackendData.data;
// Sometimes the backend knows the relation by a different name, e.g. the relation is called
// `activities`, but the name in the backend is `activity`.
// In that case, you can add `static backendResourceName = 'activity';` to that model.
const realBackendName =
rel.constructor.backendResourceName || relBackendName;
relations[realBackendName] = relBackendData.data;
forIn(relBackendData.relations, (relB, key) => {
relations[key] = relations[key]
? relations[key].concat(relB)
Expand Down Expand Up @@ -974,8 +995,8 @@ let Model = ((_class = ((_temp = _class2 = class Model {
this[currentRel].clear();
});
}
}), (_class2.primaryKey =
'id'), _temp)), ((_descriptor = _applyDecoratedDescriptor(
}), (_class2.primaryKey = 'id'), (_class2.backendResourceName =
''), _temp)), ((_descriptor = _applyDecoratedDescriptor(
_class.prototype,
'__backendValidationErrors',
[observable],
Expand Down
35 changes: 28 additions & 7 deletions dist/mobx-spine.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
var _descriptor2$1;
var _descriptor3;
var _descriptor4;
var _class2$1;
var _temp$1;

function _initDefineProp$1(target, property, descriptor, context) {
if (!descriptor) return;
Expand Down Expand Up @@ -90,16 +92,21 @@

const AVAILABLE_CONST_OPTIONS = ['relations', 'limit'];

let Store = ((_class$1 = class Store {
// Holds the fetch parameters
let Store = ((_class$1 = ((_temp$1 = _class2$1 = class Store {
get isLoading() {
return this.__pendingRequestCount > 0;
}

// Holds the fetch parameters
get length() {
return this.models.length;
}

set backendResourceName(v) {
throw new Error(
'`backendResourceName` should be a static property on the store.'
);
}

constructor(options = {}) {
_initDefineProp$1(this, 'models', _descriptor$1, this);

Expand Down Expand Up @@ -387,7 +394,8 @@
}
return this.models[index];
}
}), ((_descriptor$1 = _applyDecoratedDescriptor$1(
}), (_class2$1.backendResourceName =
''), _temp$1)), ((_descriptor$1 = _applyDecoratedDescriptor$1(
_class$1.prototype,
'models',
[mobx.observable],
Expand Down Expand Up @@ -590,6 +598,8 @@

let Model = ((_class = ((_temp = _class2 = class Model {
// Holds activated - nested - relations (e.g. `['animal', 'animal.breed']`)

// How the model is known at the backend. This is useful when the model is in a relation that has a different name.
get url() {
const id = this[this.constructor.primaryKey];
return `${this.urlRoot}${id ? `${id}/` : ''}`;
Expand All @@ -613,6 +623,12 @@
);
}

set backendResourceName(v) {
throw new Error(
'`backendResourceName` should be a static property on the model.'
);
}

casts() {
return {};
}
Expand Down Expand Up @@ -749,7 +765,12 @@
data[relBackendName] = myNewId;
}
const relBackendData = rel.toBackendAll(myNewId);
relations[relBackendName] = relBackendData.data;
// Sometimes the backend knows the relation by a different name, e.g. the relation is called
// `activities`, but the name in the backend is `activity`.
// In that case, you can add `static backendResourceName = 'activity';` to that model.
const realBackendName =
rel.constructor.backendResourceName || relBackendName;
relations[realBackendName] = relBackendData.data;
lodash.forIn(relBackendData.relations, (relB, key) => {
relations[key] = relations[key]
? relations[key].concat(relB)
Expand Down Expand Up @@ -1010,8 +1031,8 @@
this[currentRel].clear();
});
}
}), (_class2.primaryKey =
'id'), _temp)), ((_descriptor = _applyDecoratedDescriptor(
}), (_class2.primaryKey = 'id'), (_class2.backendResourceName =
''), _temp)), ((_descriptor = _applyDecoratedDescriptor(
_class.prototype,
'__backendValidationErrors',
[mobx.observable],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-spine",
"version": "0.8.0",
"version": "0.9.0",
"license": "ISC",
"author": "Kees Kluskens <[email protected]>",
"description": "MobX with support for models, relations and an API.",
Expand Down

0 comments on commit ca168fa

Please sign in to comment.