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

meta tags manager #123

Merged
merged 4 commits into from
Oct 16, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rvm:
- 2.2.2
install:
- bundle install
- npm install -g npm
- npm install
- cd client && npm run build:client
- npm run build:server
Expand Down
11 changes: 3 additions & 8 deletions client/app/utils/metaTagsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ const MetaTagsManager = {
* @returns {String} - CSRF Token.
*/
getCSRFToken() {
const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
const meta = metas[i];
if (meta.getAttribute('name') === 'csrf-token') {
return meta.getAttribute('content');
}
}
const token = Array.from(document.getElementsByTagName('meta'))
Copy link
Member Author

Choose a reason for hiding this comment

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

@josiasds Let's consider the lodash syntax from this.

Interesting find from @dylangrafmyre on the CI regarding Array.from.

Copy link
Member

Choose a reason for hiding this comment

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

@justin808 I'm not sure we should add lodash only to replace Array.from by _.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.

You're right. We don't have lodash in this project.

_.find(document.getElementsByTagName('meta'), tag => tag.name === 'csrf-token')

or

_(document.getElementsByTagName('meta')).find(tag => tag.name === 'csrf-token')

2015-10-16_12-09-15

I really like Lodash. I wouldn't suggest this otherwise. That being said, we don't need it give some features in ES6.

Because I want this example to be a real starter kit showing off Webpack/Npm/React integration, I think this is worth considering.

Let's see what @mapreal19, @alexfedoseev, @samnang, @dylangrafmyre Think about this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Even better from the lodash source, @jdalton:

_.find(document.querySelectorAll('meta'), 'name', 'csrf-token')

.find(tag => tag.name === 'csrf-token');

return null;
return token ? token.content : null;
},
};

Expand Down
Loading