Add support for server-side rendering [Fix #7]

release
Etienne Lemay 2016-10-03 20:49:35 -04:00
parent 29063f2f64
commit f31a359f78
4 changed files with 12 additions and 8 deletions

View File

@ -29,9 +29,9 @@ export default class Category extends React.Component {
}
shouldComponentUpdate(nextProps, nextState) {
var { name, perLine, emojis, emojiProps } = this.props,
var { name, perLine, hasStickyPosition, emojis, emojiProps } = this.props,
{ skin, size, sheetURL } = emojiProps,
{ perLine: nextPerLine, emojis: nextEmojis, emojiProps: nextEmojiProps } = nextProps,
{ perLine: nextPerLine, hasStickyPosition: nextHasStickyPosition, emojis: nextEmojis, emojiProps: nextEmojiProps } = nextProps,
{ skin: nextSkin, size: nextSize, sheetURL: nextSheetURL } = nextEmojiProps,
shouldUpdate = false
@ -43,7 +43,7 @@ export default class Category extends React.Component {
shouldUpdate = !(emojis == nextEmojis)
}
if (skin != nextSkin || size != nextSize || sheetURL != nextSheetURL) {
if (skin != nextSkin || size != nextSize || sheetURL != nextSheetURL || hasStickyPosition != nextHasStickyPosition) {
shouldUpdate = true
}

View File

@ -19,7 +19,6 @@ const CATEGORIES = [
export default class Picker extends React.Component {
constructor(props) {
super(props)
this.testStickyPosition()
this.state = {
skin: store.get('skin') || props.skin,
@ -35,6 +34,7 @@ export default class Picker extends React.Component {
componentDidMount() {
if (this.state.firstRender) {
this.testStickyPosition()
this.firstRenderTimeout = setTimeout(() => {
this.setState({ firstRender: false })
}, 60)

View File

@ -1,5 +1,8 @@
const NAMESPACE = 'emoji-mart'
var isLocalStorageSupported = typeof window !== 'undefined' &&
'localStorage' in window
function update(state) {
for (let key in state) {
let value = state[key]
@ -8,13 +11,12 @@ function update(state) {
}
function set(key, value) {
if (!('localStorage' in window)) return
if (!isLocalStorageSupported) return
window.localStorage[`${NAMESPACE}.${key}`] = JSON.stringify(value)
}
function get(key) {
if (!('localStorage' in window)) return
if (!isLocalStorageSupported) return
var value = window.localStorage[`${NAMESPACE}.${key}`]
if (value) {

View File

@ -5,7 +5,9 @@
// MIT license
(function() {
var isWindowAvailable = typeof window !== 'undefined'
isWindowAvailable && (function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {