-
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
Add findByTag and replace underscore with lodash #3
Conversation
Next I'm looking at pagination... 😉 |
if (tag) { | ||
var results = _.where(blogs, { tags: [tag] }); | ||
|
||
if (results !== null && results !== undefined) { |
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.
Does lo-dash's where
ever return null
or undefined
? Seems to always return an array, either with items if something is matched, or empty otherwise. Given that no tag
argument would mean tag === undefined
, could we simplify the entire function to:
var findByTag = function(tag) {
_reinit();
return _.where(blogs, { tags: [tag] });
};
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.
You're right! https://github.com/lodash/lodash/blob/2.4.1/dist/lodash.compat.js#L3483 looks like where
is an alias for filter
which always returns the array. Will update and commit...
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.
Awesome 👍
Nice, this is a good idea :) I've left one comment regarding Thanks! |
Done! merge away.... and I'll change that in my sitemark repo too! |
Thanks again James :) |
Add findByTag and replace underscore with lodash
Allows finding articles by tag. I had to replace
underscore
withlodash
, but see this issue which has a long discussion about it and its performance, and the conclusion was to switch to lodash.Url this uses is
/tag/{{tag}}