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

Comments

Projects
None yet
4 participants
@isadovskiy

isadovskiy commented May 12, 2014

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 from Improvement can.list.pushAll and can.list.unshiftAll shortcuts to Improvement: can.list.pushAll and can.list.unshiftAll shortcuts May 12, 2014

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor May 13, 2014

Contributor

concat opeartion maybe added as well

Contributor

whitecolor commented May 13, 2014

concat opeartion maybe added as well

@isadovskiy

This comment has been minimized.

Show comment
Hide comment
@isadovskiy

isadovskiy May 13, 2014

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.

isadovskiy commented May 13, 2014

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.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor May 13, 2014

Contributor

good

Contributor

whitecolor commented May 13, 2014

good

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer May 13, 2014

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.

Contributor

justinbmeyer commented May 13, 2014

@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.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor May 14, 2014

Contributor

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.

Contributor

whitecolor 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

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Aug 26, 2014

Contributor

Closing for #192.

Contributor

justinbmeyer commented Aug 26, 2014

Closing for #192.

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