Last active
September 6, 2018 14:44
-
-
Save pl12133/dc6e91f5ea903067c1475ec8bba413dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { h, Component } from 'preact'; | |
| function withScript(src) { | |
| return (Child) => class ScriptLoader extends Component { | |
| static script; | |
| componentWillMount() { | |
| if (typeof ScriptLoader.script === 'undefined') { | |
| ScriptLoader.script = document.createElement('script'); | |
| ScriptLoader.script.src = src; | |
| ScriptLoader.script.addEventListener('load', () => this.setState({ loaded: true })); | |
| document.body.appendChild(ScriptLoader.script); | |
| } | |
| } | |
| render(props, { loaded }) { | |
| return loaded && <Child {...props} /> | |
| } | |
| } | |
| } | |
| /** | |
| withScript('http://n12v.com/focus-transition/flying-focus.js'); | |
| withScript('http://nv.github.io/focus-snail/standalone/focus-snail.js'); | |
| withScript('http://nv.github.io/focus-hug/standalone/focus-hug.js'); | |
| withScript('http://nv.github.io/focus-zoom/focus-zoom.js'); | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment