mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-10 07:05:35 +00:00
Continued porting to react, approaching beta
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
import React from 'react';
|
||||
import shallowEqual from '../utils/shallowEqual';
|
||||
import { shallowEqual } from '../utils/UtilityFunctions';
|
||||
|
||||
/**
|
||||
* @class Abstract TranslatedComponent
|
||||
* Abstract Translated Component
|
||||
*/
|
||||
export default class TranslatedComponent extends React.Component {
|
||||
|
||||
static contextTypes = {
|
||||
language: React.PropTypes.object.isRequired,
|
||||
sizeRatio: React.PropTypes.number.isRequired
|
||||
}
|
||||
sizeRatio: React.PropTypes.number.isRequired,
|
||||
openMenu: React.PropTypes.func.isRequired,
|
||||
closeMenu: React.PropTypes.func.isRequired,
|
||||
showModal: React.PropTypes.func.isRequired,
|
||||
hideModal: React.PropTypes.func.isRequired,
|
||||
tooltip: React.PropTypes.func.isRequired,
|
||||
termtip: React.PropTypes.func.isRequired,
|
||||
onWindowResize: React.PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
/**
|
||||
* Created an instance of a Translated Component. This is an abstract class.
|
||||
@@ -23,9 +30,9 @@ export default class TranslatedComponent extends React.Component {
|
||||
/**
|
||||
* Determine if the context change incldues a language or size change
|
||||
* @param {object} nextContext The incoming / next context
|
||||
* @return {boolean} true if the language has changed
|
||||
* @return {boolean} true if the language has changed
|
||||
*/
|
||||
didContextChange(nextContext){
|
||||
didContextChange(nextContext) {
|
||||
return nextContext.language !== this.context.language || nextContext.sizeRatio != this.context.sizeRatio;
|
||||
}
|
||||
|
||||
@@ -34,14 +41,12 @@ export default class TranslatedComponent extends React.Component {
|
||||
* props, state, or context changes. This method performs a shallow comparison to
|
||||
* determine change.
|
||||
*
|
||||
* @param {object} nextProps
|
||||
* @param {objec} nextState
|
||||
* @param {objec} nextContext
|
||||
* @param {object} nextProps Next/Incoming Properties
|
||||
* @param {objec} nextState Next/Incoming State
|
||||
* @param {objec} nextContext Next/Incoming Context
|
||||
* @return {boolean} True if props, state, or context has changed
|
||||
*/
|
||||
shouldComponentUpdate(nextProps, nextState, nextContext) {
|
||||
return !shallowEqual(this.props, nextProps)
|
||||
|| !shallowEqual(this.state, nextState)
|
||||
|| this.didContextChange(nextContext);
|
||||
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState) || this.didContextChange(nextContext);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user