-
Notifications
You must be signed in to change notification settings - Fork 1
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
get rid of can-util #75
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 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 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 |
---|---|---|
|
@@ -8,14 +8,11 @@ var canEvent = require('can-event-queue/map/map'); | |
var ObservationRecorder = require('can-observation-recorder'); | ||
|
||
var CID = require('can-cid'); | ||
var isPromise = require('can-util/js/is-promise/is-promise'); | ||
var makeArray = require('can-util/js/make-array/make-array'); | ||
var assign = require('can-util/js/assign/assign'); | ||
var types = require('can-types'); | ||
var each = require('can-util/js/each/each'); | ||
var canReflect = require('can-reflect'); | ||
var assign = require('can-assign'); | ||
var types = require('can-types'); | ||
var canSymbol = require('can-symbol'); | ||
var CIDMap = require("can-util/js/cid-map/cid-map"); | ||
var CIDMap = require("can-cid/map/map"); | ||
|
||
|
||
// Helpers for `observable` lists. | ||
|
@@ -54,11 +51,11 @@ var List = Map.extend( | |
instances = instances || []; | ||
var teardownMapping; | ||
|
||
if (isPromise(instances)) { | ||
if (canReflect.isPromise(instances)) { | ||
this.replace(instances); | ||
} else { | ||
teardownMapping = instances.length && mapHelpers.addToMap(instances, this); | ||
this.push.apply(this, makeArray(instances || [])); | ||
this.push.apply(this, canReflect.toArray(instances || [])); | ||
} | ||
|
||
if (teardownMapping) { | ||
|
@@ -167,7 +164,7 @@ var List = Map.extend( | |
return canReflect.serialize(this, CIDMap); | ||
}, | ||
splice: function (index, howMany) { | ||
var args = makeArray(arguments), | ||
var args = canReflect.toArray(arguments), | ||
added =[], | ||
i, len, listIndex, | ||
allSame = args.length > 2; | ||
|
@@ -225,10 +222,10 @@ var List = Map.extend( | |
getArgs = function (args) { | ||
return args[0] && Array.isArray(args[0]) ? | ||
args[0] : | ||
makeArray(args); | ||
canReflect.toArray(args); | ||
}; | ||
// Create `push`, `pop`, `shift`, and `unshift` | ||
each({ | ||
canReflect.eachKey({ | ||
/** | ||
* @function can-list.prototype.push push | ||
* @parent can-list.prototype | ||
|
@@ -347,7 +344,7 @@ each({ | |
}; | ||
}); | ||
|
||
each({ | ||
canReflect.eachKey({ | ||
/** | ||
* @function can-list.prototype.pop pop | ||
* @parent can-list.prototype | ||
|
@@ -533,7 +530,7 @@ assign(List.prototype, { | |
* ``` | ||
*/ | ||
reverse: function() { | ||
var list = [].reverse.call(makeArray(this)); | ||
var list = [].reverse.call(canReflect.toArray(this)); | ||
return this.replace(list); | ||
}, | ||
|
||
|
@@ -604,12 +601,12 @@ assign(List.prototype, { | |
MapType = this.constructor.Map; | ||
// Go through each of the passed `arguments` and | ||
// see if it is list-like, an array, or something else | ||
each(arguments, function(arg) { | ||
canReflect.each(arguments, function(arg) { | ||
if((canReflect.isObservableLike(arg) && canReflect.isListLike(arg)) || Array.isArray(arg)) { | ||
// If it is list-like we want convert to a JS array then | ||
// pass each item of the array to serializeNonTypes | ||
var arr = (canReflect.isObservableLike(arg) && canReflect.isListLike(arg)) ? makeArray(arg) : arg; | ||
each(arr, function(innerArg) { | ||
var arr = (canReflect.isObservableLike(arg) && canReflect.isListLike(arg)) ? canReflect.toArray(arg) : arg; | ||
canReflect.each(arr, function(innerArg) { | ||
serializeNonTypes(MapType, innerArg, args); | ||
}); | ||
} | ||
|
@@ -624,7 +621,7 @@ assign(List.prototype, { | |
// as well (We know it should be list-like), then | ||
// concat with our passed in args, then pass it to | ||
// list constructor to make it back into a list | ||
return new this.constructor(Array.prototype.concat.apply(makeArray(this), args)); | ||
return new this.constructor(Array.prototype.concat.apply(canReflect.toArray(this), args)); | ||
}, | ||
|
||
/** | ||
|
@@ -724,7 +721,7 @@ assign(List.prototype, { | |
* ``` | ||
*/ | ||
replace: function (newList) { | ||
if (isPromise(newList)) { | ||
if (canReflect.isPromise(newList)) { | ||
if(this._promise) { | ||
this._promise.__isCurrentPromise = false; | ||
} | ||
|
@@ -737,7 +734,7 @@ assign(List.prototype, { | |
} | ||
}); | ||
} else { | ||
this.splice.apply(this, [0, this.length].concat(makeArray(newList || []))); | ||
this.splice.apply(this, [0, this.length].concat(canReflect.toArray(newList || []))); | ||
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. Same with this line; we shouldn’t pass an empty array to 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. Fixed! |
||
} | ||
|
||
return this; | ||
|
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
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.
It’d be nice if we changed this to check for
instances
, something like: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.
Fixed!