-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[WIP] Refactor Meta's deps structure to an array of arrays. #13659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ let members = { | |
| mixins: inheritedMap, | ||
| bindings: inheritedMap, | ||
| values: inheritedMap, | ||
| deps: inheritedMapOfMaps, | ||
| deps: inheritedArrayOfArrays, | ||
| chainWatchers: ownCustomObject, | ||
| chains: inheritedCustomObject, | ||
| tag: ownCustomObject | ||
|
|
@@ -176,45 +176,80 @@ Meta.prototype._findInherited = function(key, subkey) { | |
|
|
||
| export const UNDEFINED = symbol('undefined'); | ||
|
|
||
| // Implements a member that provides a lazily created map of maps, | ||
| // Implements a member that provides a lazily created array of arrays, | ||
| // with inheritance at both levels. | ||
| function inheritedMapOfMaps(name, Meta) { | ||
| function inheritedArrayOfArrays(name, Meta) { | ||
| let key = memberProperty(name); | ||
| let capitalized = capitalize(name); | ||
|
|
||
| Meta.prototype['write' + capitalized] = function(subkey, itemkey, value) { | ||
| let outerMap = this._getOrCreateOwnMap(key); | ||
| let innerMap = outerMap[subkey]; | ||
| if (!innerMap) { | ||
| innerMap = outerMap[subkey] = new EmptyObject(); | ||
| Meta.prototype['write' + capitalized] = function(subkey, itemKey, value) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can you do |
||
| let keyArray = this[key]; | ||
| if (!keyArray) { | ||
| keyArray = this[key] = []; | ||
| } | ||
| innerMap[itemkey] = value; | ||
|
|
||
| for (let i = 0; i < keyArray.length; i++) { | ||
| if (keyArray[i][0] === subkey) { | ||
| let subkeyArray = keyArray[i][1]; | ||
|
|
||
| for (let j = 0; j < subkeyArray.length; j++) { | ||
| if (subkeyArray[j][0] === itemKey) { | ||
| subkeyArray[j][1] = value; | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| subkeyArray.push([itemKey, value]); | ||
| } | ||
| } | ||
|
|
||
| // add the subkey to the outerArray | ||
| keyArray.push([ | ||
| subkey, | ||
| // array of itemKeys for the subkey | ||
| [ | ||
| [itemKey, value] | ||
| ] | ||
| ]); | ||
| }; | ||
|
|
||
| Meta.prototype['peek' + capitalized] = function(subkey, itemkey) { | ||
| Meta.prototype['peek' + capitalized] = function(subkey, itemKey) { | ||
| let pointer = this; | ||
| while (pointer !== undefined) { | ||
| let map = pointer[key]; | ||
| if (map) { | ||
| let value = map[subkey]; | ||
| if (value) { | ||
| if (value[itemkey] !== undefined) { | ||
| return value[itemkey]; | ||
| let keyArray = pointer[key]; | ||
| if (keyArray) { | ||
| for (let i = 0; i < keyArray.length; i++) { | ||
| if (keyArray[i][0] === subkey) { | ||
| let subkeyArray = keyArray[i][1]; | ||
|
|
||
| for (let j = 0; j < subkeyArray.length; j++) { | ||
| if (subkeyArray[j][0] === itemKey) { | ||
| return subkeyArray[j][1]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pointer = pointer.parent; | ||
| } | ||
| }; | ||
|
|
||
| Meta.prototype['has' + capitalized] = function(subkey) { | ||
| let pointer = this; | ||
| while (pointer !== undefined) { | ||
| if (pointer[key] && pointer[key][subkey]) { | ||
| return true; | ||
| let keyArray = pointer[key]; | ||
| if (keyArray) { | ||
| for (let i = 0; i < keyArray.length; i++) { | ||
| if (keyArray[i][0] === subkey) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pointer = pointer.parent; | ||
| } | ||
|
|
||
| return false; | ||
| }; | ||
|
|
||
|
|
@@ -228,20 +263,26 @@ Meta.prototype._forEachIn = function(key, subkey, fn) { | |
| let seen = new EmptyObject(); | ||
| let calls = []; | ||
| while (pointer !== undefined) { | ||
| let map = pointer[key]; | ||
| if (map) { | ||
| let innerMap = map[subkey]; | ||
| if (innerMap) { | ||
| for (let innerKey in innerMap) { | ||
| if (!seen[innerKey]) { | ||
| seen[innerKey] = true; | ||
| calls.push([innerKey, innerMap[innerKey]]); | ||
| let keyArray = pointer[key]; | ||
| if (keyArray) { | ||
| for (let i = 0; i < keyArray.length; i++) { | ||
| if (keyArray[i][0] === subkey) { | ||
| let subkeyArray = keyArray[i][1]; | ||
|
|
||
| for (let j = 0; j < subkeyArray.length; j++) { | ||
| let innerKey = subkeyArray[j][0]; | ||
|
|
||
| if (!seen[innerKey]) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
| seen[innerKey] = true; | ||
| calls.push(subkeyArray[j]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| pointer = pointer.parent; | ||
| } | ||
|
|
||
| for (let i = 0; i < calls.length; i++) { | ||
| let [innerKey, value] = calls[i]; | ||
| fn(innerKey, value); | ||
|
|
@@ -343,7 +384,7 @@ if (isEnabled('mandatory-setter')) { | |
| } | ||
|
|
||
| // choose the one appropriate for given platform | ||
| let setMeta = function(obj, meta) { | ||
| function setMeta(obj, meta) { | ||
| // if `null` already, just set it to the new value | ||
| // otherwise define property first | ||
| if (obj[META_FIELD] !== null) { | ||
|
|
@@ -355,7 +396,7 @@ let setMeta = function(obj, meta) { | |
| } | ||
|
|
||
| obj[META_FIELD] = meta; | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| Retrieves the meta hash for an object. If `writable` is true ensures the | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to just pass the capitalized name at the call site?