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

Feature UPDATE js src #5

Closed
wants to merge 8 commits into from

Conversation

andresin87
Copy link

EX: You can overwrite your jQuery version only updating the prop src

src/index.jsx Outdated
// component from the script's observers before unmounting the component.
if (observers) {
delete observers[this.scriptLoaderId];
// delete (this.constructor.scriptObservers)[url];
Copy link
Author

Choose a reason for hiding this comment

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

I think It must not be commented, but your latest test fails if I uncomment this line

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. Feel free to fix the tests necessary

@andresin87
Copy link
Author

KeepAlive

Copy link
Contributor

@jakubkottnauer jakubkottnauer left a comment

Choose a reason for hiding this comment

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

A great PR, thanks! Sorry for not getting back to you earlier. Please update yarn.lock and add a few tests for the new functionality.

src/index.jsx Outdated
@@ -36,53 +40,99 @@ export default class Script extends React.Component {
constructor(props) {
super(props);
this.scriptLoaderId = `id${this.constructor.idCount++}`; // eslint-disable-line space-unary-ops, no-plusplus
this.pkID = `script-${shortid.generate()}`;
this.unmount = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make this a separate function in the component instead of creating it in constructor

src/index.jsx Outdated
delete (this.constructor.erroredScripts)[url];
}
};
this.generate = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make this a separate function in the component instead of creating it in constructor

src/index.jsx Outdated

// If this script has been previously errored
if (errored) {
delete (this.constructor.erroredScripts)[url];
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for the parentheses

src/index.jsx Outdated

// If this script has been previously loaded
if (loaded) {
delete (this.constructor.loadedScripts)[url];
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for the parentheses

}
shouldComponentUpdate(nextProps) {
let r = false;
Object.keys(this.props).forEach((k) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be easily rewritten using Array.prototype.find() - it will shorter and even a bit faster as you won't be iterating the whole array when a positive result is found.

Copy link
Author

Choose a reason for hiding this comment

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

what do you mean?

Copy link
Contributor

@jakubkottnauer jakubkottnauer Jun 30, 2017

Choose a reason for hiding this comment

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

You can even use some which is even better, something like the following should work

shouldComponentUpdate(nextProps) {
  return Object.keys(this.props).some(k => this.props[k] !== nextProps[k] 
    && !(typeof this.props[k] === 'function' && typeof nextProps[k] === 'function'))
}

package.json Outdated
@@ -10,7 +10,7 @@
},
"scripts": {
"build": "npm run build:lib",
"build:lib": "babel src --out-dir lib",
"build:lib": "babel src --out-dir lib && uglifyjs ./lib/index.js -o ./lib/index.min.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary for a module? Webpack takes care of this for production builds

Copy link
Author

Choose a reason for hiding this comment

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

ok

src/index.jsx Outdated
// component from the script's observers before unmounting the component.
if (observers) {
delete observers[this.scriptLoaderId];
// delete (this.constructor.scriptObservers)[url];
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. Feel free to fix the tests necessary

@jakubkottnauer
Copy link
Contributor

Also please update readme :-)

@andresin87
Copy link
Author

Ok. I'll add your indications this week @jakubkottnauer.

@andresin87
Copy link
Author

I think it will solve the issue #6

@matejlauko
Copy link

@andresin87 Hi. Please what is the real world application of this?

@Bartozzz Bartozzz mentioned this pull request Aug 29, 2017
@andresin87 andresin87 closed this Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants