Skip to content
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 3 commits into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions can-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 || []));
Copy link
Member

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:

instances === undefined ? [] : canReflect.toArray(instances)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

}

if (teardownMapping) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -347,7 +344,7 @@ each({
};
});

each({
canReflect.eachKey({
/**
* @function can-list.prototype.pop pop
* @parent can-list.prototype
Expand Down Expand Up @@ -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);
},

Expand Down Expand Up @@ -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);
});
}
Expand All @@ -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));
},

/**
Expand Down Expand Up @@ -724,7 +721,7 @@ assign(List.prototype, {
* ```
*/
replace: function (newList) {
if (isPromise(newList)) {
if (canReflect.isPromise(newList)) {
if(this._promise) {
this._promise.__isCurrentPromise = false;
}
Expand All @@ -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 || [])));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this line; we shouldn’t pass an empty array to canReflect.toArray

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

}

return this;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"npmAlgorithm": "flat"
},
"dependencies": {
"can-assign": "^1.1.1",
"can-cid": "^1.1.2",
"can-construct": "^3.2.1",
"can-event-queue": "<2.0.0",
Expand All @@ -44,7 +45,6 @@
"can-stache-key": "^1.0.0",
"can-symbol": "^1.4.1",
"can-types": "^1.1.0",
"can-util": "^3.10.12",
"can-compute": "^4.0.0",
"can-queues": "<2.0.0",
"can-map": "^4.0.0"
Expand Down