Skip to content

Commit

Permalink
Add support for server-side rendering [Fix #7]
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneLem committed Oct 4, 2016
1 parent 29063f2 commit f31a359
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/utils/store.js
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/vendor/raf-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f31a359

Please sign in to comment.