Skip to content

Quick pass #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions coffee/datasource.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class @DataSource
viewModelIndex = (row * DATA_POINTS) + col

# Create the view model for this grid point
@viewModels[viewModelIndex] ||= {}
@viewModels[viewModelIndex] = {}

# Calculate the brightness of a grid point according to how far away it is from the data point
@viewModels[viewModelIndex].brightness = Math.min(1, Math.max(0, (DISPLAY_SPREAD - Math.abs(dataPoint - ROW_AMPLITUDES[row])) / DISPLAY_SPREAD))
Expand Down Expand Up @@ -91,9 +91,7 @@ class @DataSource

doWork: =>
# Produce the data
Perf.time 'producing data' if PROFILE
data = produceData.call(this)
Perf.timeEnd 'producing data' if PROFILE

# Notify anyone interested in the data
listener(data) for listener in @dataListeners
Expand Down
18 changes: 1 addition & 17 deletions coffee/native.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ dataSource = new (getDataSource())

# Attach a handler to that data source, to be called whenever new data is available
dataSource.onData (data) ->
Perf.time 'reconstructing DOM'

# Remove the visualizer from the DOM to prevent reflows
visualizerElementParent.removeChild(visualizerElement)

Expand All @@ -31,19 +29,5 @@ dataSource.onData (data) ->
# Reattach the visualizer element
visualizerElementParent.appendChild visualizerElement

Perf.timeEnd 'reconstructing DOM'

# Make the data source work as fast as possible
workIt = ->
# Work!
dataSource.doWork()

# Force a synchronous reflow, then schedule another work package.
# NOTE: This is preferable to using requestAnimationFrame, because RAF fires at funny times.
Perf.time 'redrawing' if PROFILE
forceReflow()
Perf.timeEnd 'redrawing' if PROFILE

# Schedule that next work package
setZeroTimeout workIt
workIt()
setInterval dataSource.doWork.bind(dataSource), 0
71 changes: 0 additions & 71 deletions coffee/perf.coffee

This file was deleted.

35 changes: 9 additions & 26 deletions coffee/react.coffee
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# Given a data point, produce an object where the keys represent DOM element attributes
dataPointToAttributes = (dataPoint) ->
style:
backgroundColor: "rgba(0,255,0,#{dataPoint.brightness})"
DataPoint = React.createClass
shouldComponentUpdate: (prevProps) -> prevProps.dataPoint.brightness != @props.dataPoint.brightness
render: ->
React.DOM.div (style: (backgroundColor: "rgba(0,255,0,#{@props.dataPoint.brightness})"))

# Create a React component for the visualizer
VisualizerComponent = React.createClass
getInitialState: -> { data: [] }

componentDidMount: ->
# Instantiate a data source
@dataSource = @props.dataSource or new BoringDataSource

# Attach a handler to that data source, to be called whenever new data is available
@dataSource.onData (data) =>
Perf.time 'setting state' if PROFILE
@replaceState { data: data }
Perf.timeEnd 'setting state' if PROFILE
@props.dataSource.onData (data) =>
@setState { data: data }

render: ->
# Return data point elements, wrapped in a visualizer
React.DOM.div @props, (React.DOM.div dataPointToAttributes(dataPoint) for dataPoint in @state.data)
React.DOM.div @props, ((DataPoint (dataPoint: dataPoint)) for dataPoint in @state.data)

# Create a visualizer
visualizer = new VisualizerComponent { id: 'visualizer', dataSource: (dataSource = new (getDataSource())) }
Expand All @@ -32,17 +27,5 @@ app = React.DOM.body null, [visualizer, markerButton]

# Render the app
React.renderComponent app, document.body, ->
# Make the data source work as fast as possible
workIt = ->
# Work!
dataSource.doWork()

# Force a synchronous reflow, then schedule another work package.
# NOTE: This is preferable to using requestAnimationFrame, because RAF fires at funny times.
Perf.time 'redrawing' if PROFILE
forceReflow()
Perf.timeEnd 'redrawing' if PROFILE

# Schedule that next work package
setZeroTimeout workIt
workIt()
setInterval dataSource.doWork.bind(dataSource), 0

1 change: 1 addition & 0 deletions js/fpscounter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions native.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script src="js/perf.js" type="text/javascript" charset="utf-8"></script>
<script src="js/datasource.js" type="text/javascript" charset="utf-8"></script>
<script src="js/native.js" type="text/javascript" charset="utf-8"></script>
<script src="js/fpscounter.js" type="text/javascript" charset="utf-8"></script>

</body>

Expand Down
1 change: 1 addition & 0 deletions react.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="js/datasource.js" type="text/javascript" charset="utf-8"></script>
<script src="http://fb.me/react-0.5.0.min.js" type="text/javascript"></script>
<script src="js/react.js" type="text/javascript" charset="utf-8"></script>
<script src="js/fpscounter.js" type="text/javascript" charset="utf-8"></script>

</body>

Expand Down