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

Improvement: can.list.pushAll and can.list.unshiftAll shortcuts #984

Closed
isadovskiy opened this issue May 12, 2014 · 6 comments
Closed

Improvement: can.list.pushAll and can.list.unshiftAll shortcuts #984

isadovskiy opened this issue May 12, 2014 · 6 comments
Milestone

Comments

@isadovskiy
Copy link

Currently it's not convenient to push/unshift arrays to can.List instances.

var  arr = ['one', 'two', 'three'];
some.deeply.nested.list.push.apply(some.deeply.nested.list, arr);

Can apporpriate shortcuts methods be added to can.List?

    pushAll: function (items) {
        return this.push.apply(this, items);
    },

    unshiftAll: function (items) {
        return this.unshift.apply(this, items);
    }

And then we just have

some.deeply.nested.list.pushAll(arr);
@isadovskiy isadovskiy changed the title Improvement can.list.pushAll and can.list.unshiftAll shortcuts Improvement: can.list.pushAll and can.list.unshiftAll shortcuts May 12, 2014
@wclr
Copy link
Contributor

wclr commented May 13, 2014

concat opeartion maybe added as well

@isadovskiy
Copy link
Author

From Docs: concat makes a new List with the elements of the List followed by the elements of the parameters.

So it's already in place.

@wclr
Copy link
Contributor

wclr commented May 13, 2014

good

@justinbmeyer
Copy link
Contributor

@isadovskiy Although I find myself doing the apply trick all the time ... I'm wary of having methods on "core" can.List outside of what browsers provide on Array. For example, we added filter, but filter is even in IE9: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter.

Is there a pushAll on Array?

If not, I would rather see this go in a list extension plugin that we've wanted to add since we created CanJS, but have never had the time. If you'd like to work on that, we can add things like this there.

@wclr
Copy link
Contributor

wclr commented May 14, 2014

I think such small things are not reasonable to deliver in plugin as well. It can always be placed on prototype of those classes that need it.

But List.every https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every would be useful as well as List.some https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some.

@justinbmeyer justinbmeyer added this to the 2.2.0 milestone Aug 26, 2014
@justinbmeyer
Copy link
Contributor

Closing for #192.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants