Skip to content

Commit

Permalink
chore(docz-core): remove detect onechanged
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Nov 15, 2018
1 parent 6d9bb25 commit 2001edf
Showing 1 changed file with 7 additions and 46 deletions.
53 changes: 7 additions & 46 deletions packages/docz-core/templates/root.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,15 @@ import React from 'react'
import { setConfig, hot } from 'react-hot-loader'
import Theme from '<%- theme %>'

import { imports } from './imports'
import db from './db.json'

<% if (wrapper) {%>import Wrapper from '<%- wrapper %>'<%}%>

const isDev = module.hot && process.env.NODE_ENV !== 'production'
let isHotUpdate = false
let root
if (typeof document !== 'undefined') {
root = document.querySelector('#root')
isHotUpdate = isDev && !!root.innerHTML
}

function injectUpdateStyleOnce() {
const cssText = '@-webkit-keyframes bling{0%{background-color:#d9edf7}to{background-color:#d9edf7}}@-moz-keyframes bling{0%{background-color:#d9edf7}to{background-color:#d9edf7}}@-o-keyframes bling{0%{background-color:#d9edf7}to{background-color:#d9edf7}}@keyframes bling{0%{background-color:#d9edf7}to{background-color:#d9edf7}}.detected-updated,.detected-updated pre{-webkit-animation:bling 2.5s 1;-moz-animation:bling 2.5s 1;-o-animation:bling 2.5s 1;animation:bling 2.5s 1}'
if (typeof document !== 'undefined' && !global.__INJECTED_UPDATED_CSS_TEXT__) {
const style = document.createElement('style')
style.textContent = cssText
style.type = 'text/css'
document.head.appendChild(style)
global.__INJECTED_UPDATED_CSS_TEXT__ = true
}
}

class Root extends React.Component {
componentDidUpdate() {
if (isHotUpdate && root) {
setTimeout(() => {
const updateNode = root.querySelector('.detected-updated')
if (updateNode) {
updateNode.scrollIntoView({ behavior: 'smooth' })
injectUpdateStyleOnce()
}
})
}
}
render() {
return (
<Theme
db={db}
imports={imports}
hashRouter={<%- hashRouter %>}
<% if (!isProd) {%>websocketUrl="<%- websocketUrl %>"<%}%>
<% if (wrapper) {%>wrapper={Wrapper}<%}%>
/>
)
}
}
const Root = () => (
<Theme
hashRouter={<%- hashRouter %>}
<% if (!isProd) {%>websocketUrl="<%- websocketUrl %>"<%}%>
<% if (wrapper) {%>wrapper={Wrapper}<%}%>
/>
)

// TODO: this is temporary until react-hot-loader fix hooks issues
setConfig({
Expand Down

0 comments on commit 2001edf

Please sign in to comment.