Comparing version
{ | ||
"name": "datacore", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Model library for RESTful API clients.", | ||
@@ -5,0 +5,0 @@ "author": "Mitranim", |
@@ -110,3 +110,12 @@ (function(factory) { | ||
child.prototype.$super = this.prototype; | ||
_.assign(child, this); | ||
/** | ||
* Set self as the child's prototype. This lets us carry over the statics | ||
* without having to distinguish between settable and non-settable | ||
* properties such as 'length', 'arguments', etc., which would have been | ||
* necessary because our transpiler uses Object.defineProperties to set | ||
* them, which defaults to non-enumerable. This mimics the transpiled | ||
* 'class X extends Y'. | ||
*/ | ||
child.__proto__ = this; | ||
}, | ||
@@ -178,2 +187,4 @@ writable: true, | ||
* $path(): string {return super.$path() + '/books'} | ||
* | ||
* May be called on a prototype (we do this in statics). | ||
*/ | ||
@@ -190,5 +201,5 @@ | ||
/** | ||
* Generates the record's resource url by appending the record's id (if any) | ||
* to the class's resource locator. Accepts an optional id that overrides | ||
* the record's own id. | ||
* Generates the record's resource url by appending its id (if any) to the | ||
* class's resource locator. Accepts an optional id that overrides the | ||
* record's own id. May be called on a prototype (we do this in statics). | ||
*/ | ||
@@ -378,3 +389,3 @@ | ||
/** | ||
* Load related entities specified in the $related schema. Each filter must | ||
* Loads related entities specified in the $related schema. Each filter must | ||
* be a function that returns a "maybe promise". The promise's eventual | ||
@@ -511,2 +522,4 @@ * result is assigned to self under the same key as the filter's. | ||
return _.pick(superset, function (value, key) { | ||
// Ignore non-own properties. | ||
if (!_.has(superset, key)) return false; | ||
return !_.isEqual(value, subset[key]); | ||
@@ -513,0 +526,0 @@ }); |
@@ -51,3 +51,2 @@ 'use strict' | ||
* Uses env flags to determine which mode to use. Options: | ||
* env GULP_FLOW=basic | ||
* env GULP_FLOW=server | ||
@@ -72,3 +71,3 @@ */ | ||
* The server checks much faster, BUT may not pick up new definitions | ||
* in --lib files until restarted. | ||
* in --lib files (in our case, ./declarations/) until restarted. | ||
*/ | ||
@@ -110,3 +109,3 @@ if (process.env.GULP_FLOW === 'server') { | ||
gulp.task('watch', function() { | ||
$.watch(src, gulp.series('scripts')) | ||
$.watch(src, gulp.series('scripts')) | ||
$.watch(decl, gulp.series('scripts')) | ||
@@ -113,0 +112,0 @@ }) |
{ | ||
"name": "datacore", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Model library for RESTful API clients.", | ||
@@ -35,3 +35,2 @@ "author": "Mitranim", | ||
"gulp-babel": "^4.0.0", | ||
"gulp-concat": "^2.5.2", | ||
"gulp-load-plugins": "^0.8.1", | ||
@@ -38,0 +37,0 @@ "gulp-plumber": "^0.6.6", |
@@ -8,4 +8,4 @@ ## Description | ||
**Note**: version 0.2.0 is a complete rewrite. I've slimmed the library down | ||
_tremendously_ to focus on the most vital features. See [1.0.x](tree/0.1.x) to | ||
compare. | ||
_tremendously_ to focus on the most vital features. See | ||
[1.0.x](https://github.com/Mitranim/datacore/tree/0.1.x) to compare. | ||
@@ -12,0 +12,0 @@ Datacore is packaged in a format compatible with both AngularJS and CommonJS. |
@@ -49,2 +49,4 @@ /********************************** Public ***********************************/ | ||
* $path(): string {return super.$path() + '/books'} | ||
* | ||
* May be called on a prototype (we do this in statics). | ||
*/ | ||
@@ -54,10 +56,10 @@ $path(): string {return ''} | ||
/** | ||
* Generates the record's resource url by appending the record's id (if any) | ||
* to the class's resource locator. Accepts an optional id that overrides | ||
* the record's own id. | ||
* Generates the record's resource url by appending its id (if any) to the | ||
* class's resource locator. Accepts an optional id that overrides the | ||
* record's own id. May be called on a prototype (we do this in statics). | ||
*/ | ||
$url(id?: string): string { | ||
var url = this.$path() | ||
var url: string = this.$path() | ||
var affix = id || this.$id() | ||
var affix: string = id || this.$id() | ||
if (affix) { | ||
@@ -199,3 +201,3 @@ // Mandate a string or a number to safeguard against easy errors. | ||
/** | ||
* Load related entities specified in the $related schema. Each filter must | ||
* Loads related entities specified in the $related schema. Each filter must | ||
* be a function that returns a "maybe promise". The promise's eventual | ||
@@ -219,3 +221,3 @@ * result is assigned to self under the same key as the filter's. | ||
// result to self when done. | ||
var promise = resolve(filter.call(self)) | ||
var promise: Promise = resolve(filter.call(self)) | ||
promise.then(function(value: any) { | ||
@@ -263,3 +265,3 @@ self[key] = value | ||
$readLS(): void { | ||
var value = localStorage.getItem(this.$url()) | ||
var value: ?string = localStorage.getItem(this.$url()) | ||
if (value != null) this.$init(JSON.parse(value)) | ||
@@ -340,3 +342,12 @@ } | ||
child.prototype.$super = this.prototype | ||
_.assign(child, this) | ||
/** | ||
* Set self as the child's prototype. This lets us carry over the statics | ||
* without having to distinguish between settable and non-settable | ||
* properties such as 'length', 'arguments', etc., which would have been | ||
* necessary because our transpiler uses Object.defineProperties to set | ||
* them, which defaults to non-enumerable. This mimics the transpiled | ||
* 'class X extends Y'. | ||
*/ | ||
child.__proto__ = this | ||
} | ||
@@ -356,3 +367,3 @@ | ||
// Create and extend the child class. | ||
var template = | ||
var template: string = | ||
`return function ${name}(attributes) { | ||
@@ -389,3 +400,5 @@ if (!(this instanceof ${name})) { | ||
function subtract(superset: {}, subset: {}): {} { | ||
return _.pick(superset, function(value: any, key: string) { | ||
return _.pick(superset, function(value: any, key: string): boolean { | ||
// Ignore non-own properties. | ||
if (!_.has(superset, key)) return false | ||
return !_.isEqual(value, subset[key]) | ||
@@ -403,3 +416,3 @@ }) | ||
var src: {} = _.clone(source) || {} | ||
var buffer = {} | ||
var buffer: {} = {} | ||
@@ -461,3 +474,3 @@ // Mandate that the schema is an object. | ||
if (options == null) return buffer | ||
for (var key in options) buffer[key] = options[key] | ||
for (var key: string in options) buffer[key] = options[key] | ||
return buffer | ||
@@ -472,3 +485,3 @@ } | ||
function strictSubset(object: {}): {} { | ||
var buffer = {} | ||
var buffer: {} = {} | ||
// Avoiding _.pick because it includes inherited properties. | ||
@@ -475,0 +488,0 @@ _.forOwn(object, function(value: any, key: string) { |
@@ -295,3 +295,3 @@ 'use strict' | ||
describe('$toJSON()', function() { | ||
describe('toJSON()', function() { | ||
@@ -798,6 +798,10 @@ it('takes no arguments', function() { | ||
it('copies statics from self', function() { | ||
it("sets self as the child's __proto__, making own statics available to it", function() { | ||
function child() {} | ||
Record.extend(child) | ||
expect(_.values(child)).toEqual(_.values(Record)) | ||
expect(child.__proto__).toBe(Record) | ||
expect(typeof child.readOne).toBe('function') | ||
expect(typeof child.readAll).toBe('function') | ||
expect(typeof child.extend).toBe('function') | ||
expect(typeof child.derive).toBe('function') | ||
}) | ||
@@ -804,0 +808,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
74154
2.18%9
-10%1931
1.42%1
-50%