baselinejs
Advanced tools
Comparing version 8.2.0 to 9.0.0
@@ -6,2 +6,3 @@ var _ = require( 'underscore' ); | ||
var $ = require( 'jquery' ); | ||
var whereQuery = require( 'where-query' ); | ||
@@ -291,12 +292,23 @@ require('es6-promise').polyfill(); | ||
// Return records with matching attributes. Useful for simple cases of | ||
// `filter`. | ||
where : function( attrs, first, ignoreMissingData ) { | ||
// `filter`. Unlike in underscore, if values of attrs is an array, then | ||
// a record will be included in the return if the corresponding attribute | ||
// on the record is included in the elements of attrs. | ||
where : function( attrs, options ) { | ||
var _this = this; | ||
if( _.isEmpty( attrs ) ) return first ? void 0 : []; | ||
return this[ first ? 'find' : 'filter' ]( function( thisRecordId ) { | ||
for( var key in attrs ) { | ||
if( ! ignoreMissingData && _.isUndefined( _this._recordsById[ thisRecordId ][ key ] ) ) throw new Error( 'Field \'' + key + '\' is not present for record id ' + thisRecordId + ' in table \'' + _this.collectionName + '\'.' ); | ||
if( attrs[ key ] !== _this._recordsById[ thisRecordId ][ key ] ) return false; | ||
options = _.defaults( {}, options, { | ||
first : false, | ||
ignoreMissingData : false, | ||
} ); | ||
if( _.isEmpty( attrs ) ) return options.first ? void 0 : []; | ||
return this[ options.first ? 'find' : 'filter' ]( function( thisRecordId ) { | ||
if( ! ignoreMissingData ) { | ||
for( var key in attrs ) { | ||
if( _.isUndefined( _this._recordsById[ thisRecordId ][ key ] ) ) throw new Error( 'Field \'' + key + '\' is not present for record id ' + thisRecordId + ' in table \'' + _this.collectionName + '\'.' ); | ||
} | ||
} | ||
return true; | ||
return whereQuery.matches( _this._recordsById[ thisRecordId ], attrs ); | ||
} ); | ||
@@ -307,4 +319,8 @@ }, | ||
// of `find`. | ||
findWhere : function( attrs, ignoreMissingData ) { | ||
return this.where( attrs, true, ignoreMissingData ); | ||
findWhere : function( attrs, options ) { | ||
options = _.defaults( {}, options, { | ||
ignoreMissingData : false, | ||
} ); | ||
return this.where( attrs, { first : true, ignoreMissingData : options.ignoreMissingData } ); | ||
}, | ||
@@ -311,0 +327,0 @@ |
{ | ||
"name": "baselinejs", | ||
"version": "8.2.0", | ||
"version": "9.0.0", | ||
"description": "Share code and data between the client and the server in full stack JavaScript applications.", | ||
@@ -12,3 +12,4 @@ "main": "baseline.js", | ||
"backbone-events-standalone": "^0.2.1", | ||
"class-con-leche": "~0.0.0", | ||
"matches-where-query": "^1.0.0", | ||
"class-con-leche": "^0.0.0", | ||
"es6-promise": "^4.1.1", | ||
@@ -15,0 +16,0 @@ "jquery": "^2.1.4", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118257
397
8
+ Addedmatches-where-query@^1.0.0
+ Addedmatches-where-query@1.1.5(transitive)
Updatedclass-con-leche@^0.0.0