1517 Commits

Author SHA1 Message Date
Julian Gonggrijp
00f984ee0f Reconcile #3966 with #4061 2022-02-26 00:33:03 +01:00
Julian Gonggrijp
3b358a23c4 Update the copyright years 2022-02-26 00:33:02 +01:00
Julian Gonggrijp
37af733fb9 Bump the version to 1.4.1 2022-02-25 22:12:58 +01:00
Julian Gonggrijp
19ce298f78 Address linter errors and warnings (#4251 #4246) 2022-02-18 17:15:59 +01:00
Paul Falgout
7712b8ec6c Add model changeId event
Fixes #3882
Fixes #4159

Backbone does a bit of extra work to determine when to update `_byId` on every model change event because `change:id` will not work if `idAttribute` has changed.  This causes issues as the `change` event happens after every `change:` event which means during a change the `_byId` hasn't updated.  Rather than adding complexity to collection the solution is to have the model notify with the id changes.

If adding a public event isn't desired, for an internal solution the model is aware of it's collection and could modify model.collection._byId directly within the set.

Either of these solutions seem preferrable to handling `change:[idAttribute]`

Replaces the need for:
https://github.com/jashkenas/backbone/pull/4227/files#diff-c773bb9be277f0f3f2baa308b6e0f3a486790fe99fea81ddd0ba409846250571R1205
2022-01-12 23:26:10 +09:00
Alexey
1fce745d77 Add check for this.model.prototype 2020-03-03 20:50:16 +03:00
jashkenas
0b1c2e3fce Resolve merge conflicts 2019-12-13 11:41:21 -08:00
jashkenas
5de45fc9e1 Backbone 1.4.0 2019-02-19 10:29:40 -08:00
jashkenas
c336c8a056 Allow ESLint to do its thing. 2019-02-19 09:47:24 -08:00
Rafael De Leon
2276b8dcf9 _.bind to Function.prototype.bind 2017-06-21 22:48:32 -07:00
Graeme Yeates
e524804592 Implement Model.mixin and Collection.mixin (#4024)
Combine implementation of collection and model underscore methods
2017-04-18 15:29:55 -07:00
John Boehr
e4939e4b5d Merge branch 'master' into private-listening-public-on 2017-04-04 14:28:17 -07:00
marmeladze
3141352b83 update years 2017-01-03 17:10:48 +04:00
ksladkov
7da4ed73e7 #4103 check if obj is Model in Collection.get (#4104) 2016-12-01 16:01:59 -05:00
Lee Byron
a2fc65b979 Implements the JavaScript Iterable protocol.
This introduces new methods related to Iterators on Backbone.Collection to mirror those found on Array: `values`, `keys`, `entries`, and `@@iterator`. Each of these methods will return a JavaScript Iterator, which has a `next` method, yielding the models or ids of models contained in the Collection.

The CollectionIterator is careful to use the `at()` and `modelId()` methods on the host collection rather than direct access to the `models` property, which should ensure it is resilient to creative subclassing of Backbone.Collection and future feature addition.

The [`@@iterator`](http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-symbols) method is defined using `Symbol.iterator` if it exists in the JavaScript runtime (modern browsers/node.js) and falls back to the string `"@@iterator"` which was popularized by older versions of Firefox and has become the standard fallback behavior for other third-party libraries. This ensures that Backbone can still be used across all browsers, even with use of these new methods.

Supporting Iterable allows better integration between Backbone and the most recent additions to the JavaScript language, including `for of` loops and data-collection constructor functions, as well as better integration with other third-party libraries that accept Iterables instead of only Arrays.

Fixes #3954
2016-07-21 13:33:30 -07:00
Graeme Yeates
e4c85afa6b Merge pull request #3827 from benmccormick/master
Add a preinitialize method to allow for true instance properties and ES6 classes
2016-05-06 13:10:30 -04:00
Ilia Ablamonov
57e89d86fa Fixed updating URL with uri-decoded value
Fixes #4025
2016-04-30 21:57:39 +04:00
Ben McCormick
f6d8c3e51d Add a preinitialize function to allow modifying Backbone objects before
instantiation logic is run.

This allows greater flexibility for several use cases including
- #3620
- #3685
- Easing use of ES6 classes with Backbone
2016-04-24 22:26:51 -04:00
Rak
fe908db174 Update backbone.js
* Update backbone.js

 1 ) improve the patch method
 2 ) _.size is not nessesary, bool will be better
2016-04-07 08:59:56 -04:00
Robillard, Steven
b8c054aec7 Re-minified and updated versions. 2016-04-05 13:39:15 -04:00
Justin Ridgewell
6595240268 Merge pull request #3978 from jridgewell/1.3.2-rc
Backbone 1.3.2
2016-03-12 12:09:37 -05:00
Justin Ridgewell
835b17ba46 Backbone 1.3.2 2016-03-12 12:08:51 -05:00
Graeme Yeates
1db79ddd33 Fix 1.3.1 regression with once and no context 2016-03-08 11:23:00 -05:00
Adam Miller
b3a2813290 Only pass idAttribute to collection.modelId() 2016-02-24 17:36:51 -08:00
Adam Miller
c71336641e Update to modelId()
- modelId now takes the model in question as the second argument
 - modelId will look at the model in question's idAttribute before falling back to Collection.prototype.model.modelId and then 'id'
 - Makes basic polymorphic collection work out of the box while retaining backwards compatability
2016-02-09 13:02:06 -08:00
Ash Lux
32d89dc47e When listening to numerous events and stopListening is called, then _.isEmpty is painfully slowly and assigning _listenTo to undefined isn't necessary. 2016-02-08 15:16:10 -05:00
Jeff Shen
28588e1b96 Line 1920 - Fix Spacing After Return
Fixed spacing after return to match the rest of the code
2016-02-05 11:11:57 -08:00
Craig Martin
8932ae4bc3 optimize collection get and account for edge case 2016-02-04 15:30:26 -05:00
Adam Krebs
b0161947eb Fix #3951: options.index should never exceed collection.length 2016-02-04 15:01:59 -05:00
Justin Ridgewell
92fb299c2a Use _.extend to avoid Object.prototype collisions 2016-02-03 12:56:45 -05:00
Graeme Yeates
c380607704 Merge pull request #3940 from roycetucker/patch-2
Fixing object notation for Events.once
2016-02-01 13:52:57 -05:00
Graeme Yeates
670ff30aa4 Improve collection 'update' event consistency 2016-02-01 11:33:39 -05:00
Linus-A. M. Gubenis
90cb566250 Pass added and removed models to collection update events 2016-02-01 11:18:09 -05:00
Royce Tucker
00f5c39e27 Fixing object notation for Events.once 2016-01-28 13:05:35 -06:00
Adam Krebs
82d8ec840c Merge pull request #3929 from craigmichaelmartin/avoid-redefinitions
eliminate shadowed variable declarations
2016-01-19 13:56:36 -05:00
Craig Martin
e0a5cc75ba eliminate shadowed variable declarations
Also, add eslint rule no-shadow to enforce
2016-01-19 12:34:08 -05:00
Adam Krebs
6d37e06003 Merge pull request #3928 from captbaritone/year
Update copyright year
2016-01-19 09:49:50 -05:00
Craig Martin
75666b08c9 add has method to collection 2016-01-17 12:19:36 -05:00
Jordan Eldredge
dfe0e17d09 Update copyright year 2016-01-16 20:32:52 -08:00
Justin Ridgewell
2a78313c63 Merge pull request #3886 from ClimbsRocks/patch-1
Update wording to "space-separated" to be consistent
2016-01-15 22:00:21 -05:00
Jordan Eldredge
ff555e7664 Avoid nested ternary
While looking into adding the "no-nested-ternary" ESLint rule, I realized that
this logic could be refactored a bit.

This nested ternary was introduced in pull request #3875 in order to handle
falsy returns from `parse()`.

This refactor avoids the nested ternary and also makes the intent clearer by
associating the empty array directly with `parse()`'s return.

It also more narrowly handles the falsy case (we never intended to allow you
call `set(0)` for example.)

The only down side I can see is that if `parse()` returns falsy, we will
unnecessarily slice/clone the empty array we just created.
2015-12-29 09:15:07 -08:00
Jordan Eldredge
be1f2a87c5 Add ESLint rule: eqeqeq
Underscore uses this triple-equals syntax for its module loader.
2015-12-28 21:37:17 -08:00
Jordan Eldredge
cc3419e271 Add ESLint rule: block-scoped-var
We're already pretty good about this rule, except there were two places where
we defined an `i` counter, and then reused it in a different loop.
2015-12-28 20:55:20 -08:00
Jordan Eldredge
1c66a6e127 Add ESLint warning: no-extra-parens
This is only enabled as a warning, since in some cases I think it adds clarity.
I left the "gratuitous parentheses" when they were clarifying nested ternary
operators or clarifying the evaluation order of `&&`s and `||`s.
2015-12-20 11:34:49 -08:00
Justin Ridgewell
109d1f0208 Merge pull request #3894 from captbaritone/eslint-all
Large batch of ESLint cleanups
2015-12-18 17:21:04 -05:00
Jordan Eldredge
04fe60fad5 Add ESLint rule: no-lonely-if 2015-12-18 13:27:48 -08:00
Jordan Eldredge
21f1262abe Add ESLint rule: wrap-iife (inside) 2015-12-18 10:45:41 -08:00
Jordan Eldredge
2ae117a7cb Add ESLint rule: key-spacing 2015-12-16 10:00:19 -08:00
Jordan Eldredge
b0a6274290 Non-controversial ESLint whitespace rules
In an attempt to bring our ESLint rules closer to those in Underscore, I've
started by adding some whitespace rules which don't involve any significantly
opinionated changes.
2015-12-16 07:43:26 -08:00
Preston Parry
954ee22b98 updates wording to "space-separated" to be consistent 2015-12-11 16:15:26 -08:00