-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
Add concat()
method
#4
Conversation
Thanks for the PR @mikebronner. No worries, I'll help you out 😄 Do you have a link to the |
Absolutely: laravel/framework#19318 |
src/index.js
Outdated
collection = collection.all(); | ||
} | ||
|
||
for (let iterator = 1; iterator <= collection.count(); iterator++) { |
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.
Use forEach
instead of a loop
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.
The problem with forEach in Javascript is that order can be messed up, right? I think keeping order is important.
src/index.js
Outdated
} | ||
|
||
for (let iterator = 1; iterator <= collection.count(); iterator++) { | ||
this.items.push(collection[iterator]); |
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.
Needs logic for when item is of different type
Array
Object
String
- etc.
This is a port of your Also; what happens if the collection passed to the const expected = [
4,
5,
6,
'a',
'b',
'c',
'Jonny',
'from',
'Laroe',
'Jonny',
'from',
'Laroe'
];
const firstCollection = collect([4, 5, 6]);
const secondCollection = collect(['a', 'b', 'c']);
const thirdCollection = collect([{
who: 'Jonny'
}, {
preposition: 'from'
}, {
where: 'Laroe'
}]);
firstCollection
.concat(secondCollection)
.concat(thirdCollection)
.concat(thirdCollection);
expect(firstCollection.count()).to.eql(12);
expect(firstCollection.all()).to.eql(expected); |
Sounds good, I'll work on the port test. That test is indeed already a hybrid test, is it no? Or did you mean something else? |
Yes it is. Sorry my bad. |
@ecrmnn OK, made the requested updates. Let me know what you think. I updated the code to ignore anything that is not iterable. Laravel with throw an exception, and of course the developer will catch it. Was thinking the same would apply here. This is essentially "silently failing" now, which could be considered poor practice and the developer wouldn't be aware of the problem. Any suggestions? Also, not sure how to resolve the conflicts. I added in the missing code, but not sure what github expects in addition. Thanks :) |
The tests are failing for me? Am I missing something? |
@ecrmnn I don't know how to run the tests locally, I'm unfamiliar with JS testing. :( |
@mikebronner Sounds like a great opportunity to learn :-) |
@mikeerickson Perhaps you would like to help out on this one? I don't have the bandwidth to figure it out at the moment without some guidance on what needs to be set up. A list of commands for me to run would suffice. |
@mikebronner Most definitely, I am going to create a UMD testing workflow for the project, as well as take on the task of separating files (and tests) into separate source files. When all done, it will be a great source for you to learn from. |
If you consider the main argument that you want to add the method |
New method from a recent Laravel 5.4 patch. I'm not familiar with testing in Javascript, so I have put in some initial work to what I think it should be. Would you mind helping me a bit on this PR to flesh out the testing and make sure the implementation is working as expected?
Looking forward to your feedback :)
Thanks for creating this package! I have been thinking it would be great to have a package like this for a few years. Good to see someone better than me with Javascript took the initiative. :)