Sha256: a7c39525ef7d3f5982230abf1ab0aa7dbb6c5bdb8c43d6848db7af1f1010cade

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

REACT_CACHE = Object.create(null)

Lanes.lib.HotReload =

    remember: (klass) ->
        return unless klass::FILE
        path = klass::FILE.path.join("/") + ".js"
        if REACT_CACHE[path]
            return klass
        else
            REACT_CACHE[path] = Lanes.Vendor.ReactProxy(klass)
            return REACT_CACHE[path].get()

    replaceCss: (asset) ->
        styles = document.head.querySelectorAll("link[rel='stylesheet'][href*='#{asset.path}']")
        for link in _.toArray(styles)[0..-2]
            link.parentElement.removeChild(link)

    replaceProps: (asset) ->
        klass = Lanes.u.objectForPath(asset.path)
        if klass and REACT_CACHE[asset.path]
            REACT_CACHE[asset.path].update(klass)
            for viewport in Lanes.React.Viewport.all()
                Lanes.Vendor.deepForceUpdate(viewport.reactRoot)

    initiate: (assets) ->
        Lanes.lib.RequestAssets (_.map(assets, 'path'))...
            .then (a) =>
                for asset in assets
                    if asset.type == "css"
                        this.replaceCss(asset)
                    else
                        this.replaceProps(asset)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lanes-0.7.0 client/lanes/lib/HotReload.coffee
lanes-0.6.1 client/lanes/lib/HotReload.coffee
lanes-0.6.0 client/lanes/lib/HotReload.coffee