Skip to content

Commit

Permalink
use local linkifyIt if adding handlers, to avoid polluting the global…
Browse files Browse the repository at this point in the history
… instance

add ;s

syntax cleanup
  • Loading branch information
olslash committed May 27, 2016
1 parent 2cf3e99 commit d8b7ac4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Linkify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,37 @@ class Linkify extends React.Component {
}

componentDidMount() {
this.addCustomHandlers()
this.addCustomHandlers();
}

componentDidUpdate(nextProps) {
if (this.props.handlers !== nextProps.handlers) {
this.addCustomHandlers()
this.addCustomHandlers();
}
}

addCustomHandlers() {
const { handlers } = this.props
const { handlers } = this.props;

if (handlers.length) {
this.linkify = new LinkifyIt();
this.linkify.tlds(tlds);

handlers.forEach(handler => {
linkify.add(handler.prefix, {
this.linkify.add(handler.prefix, {
validate: handler.validate,
normalize: handler.normalize
})
})
});
});
}
}

parseCounter = 0

getMatches(string) {
return linkify.match(string);
const linkifyInstance = this.linkify || linkify;

return linkifyInstance.match(string);
}

parseString(string) {
Expand Down

0 comments on commit d8b7ac4

Please sign in to comment.