Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions src/object-cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import Clone from 'clone'
import classNames from 'classnames'

import { cellIsEditable } from './utilities'
import { cellIsEditable, isDifferent } from './utilities'

import TextDrawer from './drawers/text.jsx'
import TextEditor from './editors/text.jsx'
Expand Down Expand Up @@ -33,29 +33,17 @@ class ObjectCell extends React.Component {
}

shouldComponentUpdate(nextProps, nextState) {
let isShallowDifferent = function(objectA, objectB, exemptions) {
for (let key in objectA) {
if (exemptions && key in exemptions) {
continue
}
if (objectB[key] !== objectA[key]) {
// console.log('key', key, 'does not equal')
return true
}
}
return false
}
let propsExemptions = {
const propsExemptions = {
'onMouseDownCell': true,
'beginEdit': true,
'updateField': true,
'abortField': true,
'cellError': true,
}
if (isShallowDifferent(this.props, nextProps, propsExemptions) || isShallowDifferent(nextProps, this.props, propsExemptions)) {
if (isDifferent(this.props, nextProps, propsExemptions)) {
return true
}
if (isShallowDifferent(this.state, nextState) || isShallowDifferent(nextState, this.state)) {
if (isDifferent(this.state, nextState)) {
return true
}
return false
Expand All @@ -69,7 +57,7 @@ class ObjectCell extends React.Component {
}

handleMouseDown = (event) => {
let button = event.which || event.button
const button = event.which || event.button
event.preventDefault()
if (button === 0) {
this.props.onMouseDownCell(this.getCellRef(), event.clientX, event.clientY, event.shiftKey)
Expand All @@ -88,15 +76,15 @@ class ObjectCell extends React.Component {
}

render() {
let classes = classNames('', {
const classes = classNames('', {
'selected': this.props.selected,
'copying': this.props.copying,
'editing': this.props.editing,
})

if (this.props.editing) {
let editor = this.props.column.editor || TextEditor
let editorProps = Clone(this.props.column.editorProps || {})
const editor = this.props.column.editor || TextEditor
const editorProps = Clone(this.props.column.editorProps || {})
editorProps.value = this.props.value
editorProps.update = this.props.updateField
editorProps.abort = this.props.abortField
Expand Down Expand Up @@ -126,8 +114,8 @@ class ObjectCell extends React.Component {
</td>
)
} else {
let drawer = this.props.column.drawer || TextDrawer
let drawerProps = Clone(this.props.column.drawerProps || {})
const drawer = this.props.column.drawer || TextDrawer
const drawerProps = Clone(this.props.column.drawerProps || {})

drawerProps.value = this.props.value
drawerProps.column = this.props.column
Expand Down
29 changes: 8 additions & 21 deletions src/object-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import JQuery from 'jquery'
import classNames from 'classnames'

import { dictCount } from './utilities.js'
import { dictCount, isDifferent } from './utilities.js'

class ObjectRow extends React.Component {
static propTypes = {
Expand All @@ -29,8 +29,8 @@ class ObjectRow extends React.Component {
}

shouldComponentUpdate(nextProps, nextState) {
let isMissingColumns = function(propsA, propsB, columnsKey) {
for (let key in propsA[columnsKey]) {
const isMissingColumns = function(propsA, propsB, columnsKey) {
for (const key in propsA[columnsKey]) {
if (key in propsB[columnsKey] === false) {
// console.log('key', key, 'does not exist in both')
return true
Expand All @@ -45,20 +45,7 @@ class ObjectRow extends React.Component {
return true
}

let isShallowDifferent = function(objectA, objectB, exemptions) {
for (let key in objectA) {
if (exemptions && key in exemptions) {
continue
}
if (objectB[key] !== objectA[key]) {
// console.log('key', key, 'does not equal')
return true
}
}
return false
}

let propsExemptions = {
const propsExemptions = {
// ignore column we perform above
'selectedColumns': true,
'copyingColumns': true,
Expand All @@ -71,18 +58,18 @@ class ObjectRow extends React.Component {
'onMouseDownCell': true,
'beginEdit': true,
}
if (isShallowDifferent(this.props, nextProps, propsExemptions) || isShallowDifferent(nextProps, this.props, propsExemptions)) {
if (isDifferent(this.props, nextProps, propsExemptions)) {
return true
}
if (isShallowDifferent(this.state, nextState) || isShallowDifferent(nextState, this.state)) {
if (isDifferent(this.state, nextState)) {
return true
}
return false
}

colInRanges(column, columns, rows) {
let numRangeColumns = dictCount(columns)
let numRangeRows = dictCount(rows)
const numRangeColumns = dictCount(columns)
const numRangeRows = dictCount(rows)
if (numRangeColumns === 0 && numRangeRows === 0) {
return false
} else if (columns !== null && rows === null) {
Expand Down
17 changes: 15 additions & 2 deletions src/utilities.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function dictCount(dict) {
let count = 0
for (let _ in dict) {
for (const _ in dict) {
count++
}
return count
}

function dictFirstKey(dict) {
for (let dictKey in dict) {
for (const dictKey in dict) {
return dictKey
}
return undefined
Expand All @@ -20,8 +20,21 @@ function cellIsEditable(object, column) {
return editorIsSet && !readOnly
}

function isDifferent(objectA, objectB, exemptions) {
for (const key in objectA) {
if (exemptions && key in exemptions) {
continue
}
if (JSON.stringify(objectB[key]) !== JSON.stringify(objectA[key])) {
return true
}
}
return false
}

export {
dictCount,
dictFirstKey,
cellIsEditable,
isDifferent,
}