Skip to content

4.0.0

Choose a tag to compare

@jcbrand jcbrand released this 24 Oct 19:43
· 12 commits to master since this release
v4.0.0
e2ddb33
  • Attribute-object queries on a collection (findWhere, where, and find, filter, some,
    every, map, sortBy, countBy, groupBy, findIndex and findLastIndex when 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 made findWhere
    roughly 8 to 13 times slower than find with a hand-written predicate on a few thousand models.
    Matching semantics are unchanged: still lodash's partial, deep comparison, so nested lookups
    such as where({ FORM_TYPE: { type: 'hidden' } }) keep working. One alignment: find and
    filter given a string now read that attribute through Model.get, like the other query
    methods already did, instead of resolving it as a lodash property path over the raw attributes.

  • Model.matches no longer deep-clones its argument on every call (it uses lodash's isMatch)
    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
    its sync settles the returned promise instead of invoking the success/error callbacks
    (a rejecting custom sync, or a throwing 'sync'/'error' listener). save now bridges that
    promise to the one it hands back, the way fetch already did. Collection.create({ promise: true }),
    which delegates to save, is fixed the same way.

  • Fix fetch({ promise: true }) on a Model or Collection settling early when a callback-style sync
    returns a non-thenable (nothing, or an XHR) and invokes success/error later. The bridge from the
    sync return value to the returned promise now only engages for a thenable, so such a sync settles
    the promise through its callbacks. The same guard applies to save({ promise: true }).

  • The { promise: true } paths of fetch and save now share one bridge from the sync outcome
    to the returned promise, with two behaviour changes: a sync that rejects its promise without
    calling the callbacks now also runs the error callback and fires the 'error' event, and a
    'sync'/'error' listener (or success/error callback) that throws now rejects the promise
    instead of leaving it pending with an unhandled rejection. Collection.fetch fires 'sync' before
    resolving, as Model.fetch/save already did, so a throwing listener rejects there too.

  • Fix save({ promise: true }) and fetch({ promise: true, validate: true }) leaving the promise
    pending when the attributes returned by sync fail validation. The promise now rejects with
    validationError; the 'invalid' event fires as before.

  • save({ promise: true }) now returns a promise rejected with validationError, instead of false,
    when the attributes passed to it fail validation; create({ promise: true }) likewise returns a
    rejected promise instead of null. The callback forms still return false/null.

  • The default HTTP sync now honours both the callback and the promise contracts. It never invoked
    success/error (it passed them to fetch() as init options, which ignores them), sent an empty
    body on GET (which the Fetch API rejects outright), and resolved with the raw Response, which the
    promise bridge then merged into the model as attributes. It now sends data as query parameters on
    GET and as a JSON body otherwise, passes a parsed 2xx JSON body (null when empty) to success and
    resolves with it, and on a non-2xx response or a network failure calls error with, and rejects
    with, the error: an HTTPError (new export, carrying status and response) for the former.