From d8b7ac40a15ede8f385832a2f0e1e74e43d32c72 Mon Sep 17 00:00:00 2001 From: Mitch Robb Date: Thu, 26 May 2016 17:09:41 -0700 Subject: [PATCH] use local linkifyIt if adding handlers, to avoid polluting the global instance add ;s syntax cleanup --- src/Linkify.jsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Linkify.jsx b/src/Linkify.jsx index 2fcdd47..53841e7 100644 --- a/src/Linkify.jsx +++ b/src/Linkify.jsx @@ -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) {