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
13 changes: 8 additions & 5 deletions src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cn from 'classnames'
import raf from 'dom-helpers/util/requestAnimationFrame'
import React, { Component } from 'react'
import { findDOMNode } from 'react-dom'
import memoize from 'memoize-one'

import dates from './utils/dates'
import DayColumn from './DayColumn'
Expand Down Expand Up @@ -65,8 +66,6 @@ export default class TimeGrid extends Component {
this.state = { gutterWidth: undefined, isOverflowing: null }

this.scrollRef = React.createRef()

this.resources = Resources(props.resources, props.accessors)
}

componentWillMount() {
Expand Down Expand Up @@ -95,6 +94,7 @@ export default class TimeGrid extends Component {
raf.cancel(this.rafHandle)
this.rafHandle = raf(this.checkOverflow)
}

componentWillUnmount() {
window.removeEventListener('resize', this.handleResize)

Expand Down Expand Up @@ -144,9 +144,10 @@ export default class TimeGrid extends Component {
renderEvents(range, events, now) {
let { min, max, components, accessors, localizer } = this.props

const groupedEvents = this.resources.groupEvents(events)
const resources = this.memoizedResources(this.props.resources, accessors)
const groupedEvents = resources.groupEvents(events)

return this.resources.map(([id, resource], i) =>
return resources.map(([id, resource], i) =>
range.map((date, jj) => {
let daysEvents = (groupedEvents.get(id) || []).filter(event =>
dates.inRange(
Expand Down Expand Up @@ -233,7 +234,7 @@ export default class TimeGrid extends Component {
getNow={getNow}
localizer={localizer}
selected={selected}
resources={this.resources}
resources={this.memoizedResources(resources, accessors)}
selectable={this.props.selectable}
accessors={accessors}
getters={getters}
Expand Down Expand Up @@ -314,4 +315,6 @@ export default class TimeGrid extends Component {
})
}
}

memoizedResources = memoize((resources, accessors) => Resources(resources, accessors))
}
6 changes: 6 additions & 0 deletions src/utils/Resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default function Resources(resources, accessors) {

groupEvents(events) {
const eventsByResource = new window.Map()

if (!resources) {
// Return all events if resources are not provided
eventsByResource.set(NONE, events)
}

events.forEach(event => {
const id = accessors.resource(event) || NONE
let resourceEvents = eventsByResource.get(id) || []
Expand Down