997 Commits

Author SHA1 Message Date
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
2ea3a221ad Remove try..catch 2022-01-09 20:17:55 +03:00
Alexey
e54031f227 Return function 2022-01-09 20:14:20 +03:00
Alexey
4515b8c20a Fix synatx error 2022-01-09 20:13:45 +03:00
Alexey
f6f5deeae9 Add test 2022-01-08 12:42:00 +03:00
jashkenas
0b1c2e3fce Resolve merge conflicts 2019-12-13 11:41:21 -08: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
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
Adam Krebs
02891a2924 cleanup some automatic test failures, fix lint issues 2016-06-20 16:17:15 -04:00
Adam Krebs
55bab76349 Upgrade Qunit to 2.0, auto-convert tests using apsdehal/qunit-migrate 2016-06-20 16:04:30 -04: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
Adam Krebs
788dc91070 Remove test elements after insterting to fix failing global tests 2016-03-29 14:55:41 -04:00
Adam Krebs
a640b3bdd4 use _.indexOf instead of Array.prototype.indexOf in test. Fixes failing IE8 case 2016-03-29 14:50:06 -04: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
Adam Krebs
8d8b854abf rename at => val in test to be clearer 2016-02-04 17:16:06 -05:00
Craig Martin
8932ae4bc3 optimize collection get and account for edge case 2016-02-04 15:30:26 -05:00
Craig Martin
47fb04a373 fix failing linting tests 2016-02-04 15:16:41 -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
Justin Ridgewell
67790b27de Merge pull request #3945 from jridgewell/collection-has-test-fix
Use strictEqual in Collection#has Tests
2016-02-02 11:27:19 -05:00
Justin Ridgewell
2f85060e59 Upgrade vendor QUnit 2016-02-02 11:21:37 -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
d2099dd283 Adding a unit test for once with object notation 2016-01-30 14:37:37 -06:00
Craig Martin
1aa7f7685a add tests solidifying behavior for modelId with polymorphic models 2016-01-20 09:23:50 -05: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
Craig Martin
75666b08c9 add has method to collection 2016-01-17 12:19:36 -05: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
89d50840b6 Add ESLint rule: dot-notation 2015-12-28 21:09:44 -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
Jordan Eldredge
37465828d6 Add ESLint warning for quoted keys to tests
I've opted to leave the quotes and associated warnings in the case where the
keys include protected words or integers.
2015-12-18 13:27:48 -08:00
Jordan Eldredge
9eb9124ec9 Enforce camelCase ESLint rule in tests 2015-12-18 13:27:48 -08:00
Jordan Eldredge
42392c3aad Reenable already passing ESLint rules for tests
Previous changes made these exceptions obsolete.
2015-12-18 13:27:48 -08:00
Jordan Eldredge
3dbdfab21b Enable ESLint semicolons for tests 2015-12-18 13:27:48 -08:00
Jordan Eldredge
d91405d54f Enable ESLint rule: 'quotes' for tests
These changes were done automatically by ESLint's `--fix` tag. Thanks ESLint!
2015-12-18 13:27:48 -08:00
Jordan Eldredge
7dbdd0ac6b Add ESLint rule: no-undef 2015-12-18 13:27:48 -08:00
Adam Krebs
12da1e3eb1 remove superfluous spaces from model test 2015-12-18 12:58:04 -05:00
Jordan Eldredge
2f5cd8bee9 Enable ESLint rule: new-cap
Constructor functions must start with a capital letter.
2015-12-18 08:35:28 -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