Repository navigation
4.0.0
-
Attribute-object queries on a collection (
findWhere,where, andfind,filter,some,
every,map,sortBy,countBy,groupBy,findIndexandfindLastIndexwhen given an
object) now build their lodash matcher once per scan instead of once per model visited. Each
per-model build deep-cloned the attributes object and walked its keys, which madefindWhere
roughly 8 to 13 times slower thanfindwith a hand-written predicate on a few thousand models.
Matching semantics are unchanged: still lodash's partial, deep comparison, so nested lookups
such aswhere({ FORM_TYPE: { type: 'hidden' } })keep working. One alignment:findand
filtergiven a string now read that attribute throughModel.get, like the other query
methods already did, instead of resolving it as a lodash property path over the raw attributes. -
Model.matchesno longer deep-clones its argument on every call (it uses lodash'sisMatch)
and its signature now admits the predicate function it has always accepted at runtime. The
undocumented lodash string and[key, value]shorthand forms are no longer supported. -
Fix
Model.save({ promise: true })hanging forever, and leaking an unhandled rejection, when
itssyncsettles the returned promise instead of invoking thesuccess/errorcallbacks
(a rejecting customsync, or a throwing'sync'/'error'listener).savenow bridges that
promise to the one it hands back, the wayfetchalready did.Collection.create({ promise: true }),
which delegates tosave, is fixed the same way. -
Fix
fetch({ promise: true })on a Model or Collection settling early when a callback-stylesync
returns a non-thenable (nothing, or an XHR) and invokessuccess/errorlater. The bridge from the
syncreturn value to the returned promise now only engages for a thenable, so such asyncsettles
the promise through its callbacks. The same guard applies tosave({ promise: true }). -
The
{ promise: true }paths offetchandsavenow share one bridge from thesyncoutcome
to the returned promise, with two behaviour changes: asyncthat rejects its promise without
calling the callbacks now also runs theerrorcallback and fires the'error'event, and a
'sync'/'error'listener (orsuccess/errorcallback) that throws now rejects the promise
instead of leaving it pending with an unhandled rejection.Collection.fetchfires'sync'before
resolving, asModel.fetch/savealready did, so a throwing listener rejects there too. -
Fix
save({ promise: true })andfetch({ promise: true, validate: true })leaving the promise
pending when the attributes returned bysyncfail validation. The promise now rejects with
validationError; the'invalid'event fires as before. -
save({ promise: true })now returns a promise rejected withvalidationError, instead offalse,
when the attributes passed to it fail validation;create({ promise: true })likewise returns a
rejected promise instead ofnull. The callback forms still returnfalse/null. -
The default HTTP
syncnow honours both the callback and the promise contracts. It never invoked
success/error(it passed them tofetch()as init options, which ignores them), sent an empty
body on GET (which the Fetch API rejects outright), and resolved with the rawResponse, which the
promise bridge then merged into the model as attributes. It now sendsdataas query parameters on
GET and as a JSON body otherwise, passes a parsed 2xx JSON body (nullwhen empty) tosuccessand
resolves with it, and on a non-2xx response or a network failure callserrorwith, and rejects
with, the error: anHTTPError(new export, carryingstatusandresponse) for the former.