-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf2bf98
commit 21f051d
Showing
7 changed files
with
271 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
var Relationship = function () { | ||
|
||
// Setup a new Model instance | ||
function Relationship(instance, items) { | ||
_classCallCheck(this, Relationship); | ||
|
||
this.instance = instance; | ||
this.items = items; | ||
this.collection = null; | ||
} | ||
|
||
_createClass(Relationship, [{ | ||
key: "first", | ||
value: function first() { | ||
return this.getCollection().first(); | ||
} | ||
}, { | ||
key: "last", | ||
value: function last() { | ||
return this.getCollection().last(); | ||
} | ||
}, { | ||
key: "nth", | ||
value: function nth(i) { | ||
return this.getCollection().nth(i); | ||
} | ||
}, { | ||
key: "get", | ||
value: function get() { | ||
return this.getCollection().items; | ||
} | ||
}, { | ||
key: "create", | ||
value: function create(data) { | ||
// This should dynamically get the id of the extending class... | ||
// For example: user.posts().create({...}) should automagically send in the user_id with the post content | ||
return Promise.resolve(this.instance.constructor.create(data)); | ||
} | ||
}, { | ||
key: "collect", | ||
value: function collect() { | ||
return this.getCollection(); | ||
} | ||
}, { | ||
key: "getCollection", | ||
value: function getCollection() { | ||
if (!this.collection) { | ||
this.collection = this.instance.constructor.collect(this.items); | ||
} | ||
|
||
return this.collection; | ||
} | ||
}]); | ||
|
||
return Relationship; | ||
}(); | ||
|
||
exports.default = Relationship; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class Relationship{ | ||
|
||
// Setup a new Model instance | ||
constructor(instance, items) { | ||
this.instance = instance | ||
this.items = items | ||
this.collection = null | ||
} | ||
|
||
first () { | ||
return this.getCollection().first() | ||
} | ||
|
||
last () { | ||
return this.getCollection().last() | ||
} | ||
|
||
nth (i) { | ||
return this.getCollection().nth(i) | ||
} | ||
|
||
get () { | ||
return this.getCollection().items | ||
} | ||
|
||
create (data) { | ||
// This should dynamically get the id of the extending class... | ||
// For example: user.posts().create({...}) should automagically send in the user_id with the post content | ||
return Promise.resolve(this.instance.constructor.create(data)) | ||
} | ||
|
||
collect () { | ||
return this.getCollection() | ||
} | ||
|
||
getCollection() { | ||
if(!this.collection) { | ||
this.collection = this.instance.constructor.collect(this.items) | ||
} | ||
|
||
return this.collection | ||
} | ||
} | ||
|
||
export default Relationship; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters