-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds autotracking of arrays and Ember arrays. This is useful for arrays in particular because they have an indeterminate number of tracked values, and it would be impossible to actually track all values manually. The strategy is to check any value that we get back from a tracked getter method and see if it's an array - if so, we push its tag directly onto the stack. Later on, if the array is marked dirty via `pushObject` or `shiftObject` or some other method, it'll invalidate the autotrack stack that included the array. The one scenario this strategy does _not_ work with current is _creating_ an array in a getter dynamically: ```js class Foo { get bar() { if (!this._bar) { this._bar = []; } return this._bar; } } ``` In practice, these cases should be fairly rare, since getters should typically represent derived state from some source value, which would be tracked. Computed properties/cached getters _do_ add the tag for the object as well, since their state can be more long lived, so this won't be an issue for those.
- Loading branch information
Chris Garrett
committed
Apr 19, 2019
1 parent
f0816d4
commit 8c4c3e0
Showing
14 changed files
with
193 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import symbol from './symbol'; | ||
|
||
export const EMBER_ARRAY = symbol('EMBER_ARRAY'); | ||
|
||
export function isEmberArray(obj: any) { | ||
return obj && obj[EMBER_ARRAY]; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/@ember/-internals/utils/tests/trackable-object-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { EMBER_ARRAY, isEmberArray } from '..'; | ||
import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; | ||
|
||
moduleFor( | ||
'@ember/-internals/utils Trackable Object', | ||
class extends AbstractTestCase { | ||
['@test classes'](assert) { | ||
class Test {} | ||
Test.prototype[EMBER_ARRAY] = true; | ||
|
||
let instance = new Test(); | ||
|
||
assert.equal(isEmberArray(instance), true); | ||
} | ||
} | ||
); |