-
Notifications
You must be signed in to change notification settings - Fork 10
Major performance improvements in console and TX/RX flash #198
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
+218
−35
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
350d089
Implement tx/rx flash with manual dom elements
2fast2fourier b411a99
ct and speeds
phated a0a35a0
attempt to raf the scrollTop
phated 64eaf78
Experimental auto-expanding console
2fast2fourier 1a55851
Amazing scrolling action
2fast2fourier c3ce123
Handle reset when console buffer is cleared
2fast2fourier 6b53a09
Misc cleanup
2fast2fourier 695912d
Smooth transition from sticky/backscroll and prevent scroll hitting t…
2fast2fourier a1c2fd8
Fix accidental overlap
2fast2fourier f7c2856
Remove gap between sitcky/back states
2fast2fourier 8bd8717
Fix edge case where rolling buffer would jump in console.
2fast2fourier 1bf6ff8
Remove log
2fast2fourier ef22600
Fix edge-case error in renderVisible when render is called before con…
2fast2fourier 67716fc
Fix scroller fn name
2fast2fourier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| 'use strict'; | ||
|
|
||
| var _ = require('lodash'); | ||
|
|
||
| function generateContent(lines, start, end, minLength) { | ||
| return _(lines) | ||
| .slice(start, end) | ||
| .thru(function(array){ | ||
| if(array.length < minLength){ | ||
| // pad whitespace at top of array | ||
| return _(new Array(minLength - array.length)) | ||
| .fill('\u2009') | ||
| .concat(array) | ||
| .value(); | ||
| }else{ | ||
| return array; | ||
| } | ||
| }) | ||
| .map(function(line){ | ||
| if(line.length === 0){ | ||
| // insert a blank space to prevent pre omitting a trailing newline, | ||
| // even though pre/pre-nowrap/pre-line are specified. | ||
| return '\u2009'; | ||
| } | ||
| return line; | ||
| }) | ||
| .join('\n'); | ||
| } | ||
|
|
||
| function Scroller() { | ||
| this.lines = []; | ||
| this.minVisible = 30; | ||
| this.startPosition = 0; | ||
| this.animateRequest = null; | ||
| this.sticky = true; | ||
| this.jumpToBottom = true; | ||
| this.dirty = false; | ||
| this.console = null; | ||
|
|
||
| //pre-bind functions and throttle expansion | ||
| this.refresh = this._renderVisible.bind(this); | ||
| this.scroll = this._onScroll.bind(this); | ||
| this.expand = _.throttle(this._expand.bind(this), 150, { | ||
| leading: true, | ||
| trailing: true | ||
| }); | ||
| } | ||
|
|
||
| Scroller.prototype.setLines = function(newLines) { | ||
| var len = newLines.length; | ||
| this.lines = newLines; | ||
| if(this.sticky){ | ||
| this.startPosition = Math.max(0, len - this.minVisible); | ||
| }else if(len === 1 && newLines[0].length === 0){ | ||
| // ^^ `lines` is reset to an array with one empty line. ugh. | ||
|
|
||
| // handle the reset case when lines is replaced with an empty array | ||
| // we don't have a direct event that can call this | ||
| this.reset(); | ||
| }else if(len < this.startPosition){ | ||
| // handle buffer rollover, where number of lines will go from 2048 to ~1900 | ||
| this.startPosition = Math.max(0, len - this.minVisible); | ||
| } | ||
| this.dirty = true; | ||
| }; | ||
|
|
||
| Scroller.prototype.reset = function(){ | ||
| this.startPosition = Math.max(0, this.lines.length - this.minVisible); | ||
| this.jumpToBottom = true; | ||
| this.sticky = true; | ||
| this.dirty = true; | ||
| }; | ||
|
|
||
| Scroller.prototype.requestRefresh = function(){ | ||
| if(this.console){ | ||
| this.animateRequest = requestAnimationFrame(this.refresh); | ||
| } | ||
| }; | ||
|
|
||
| Scroller.prototype._renderVisible = function(){ | ||
| this.animateRequest = null; | ||
| if(this.dirty && this.console){ | ||
| var top = this.console.scrollTop; | ||
| if(this.sticky){ | ||
| this.startPosition = Math.max(0, this.lines.length - this.minVisible); | ||
| } | ||
| this.console.innerHTML = generateContent(this.lines, this.startPosition, this.lines.length, this.minVisible); | ||
| if(this.jumpToBottom){ | ||
| this.console.scrollTop = 2000; | ||
| this.jumpToBottom = false; | ||
| }else if(!this.sticky && this.startPosition > 0 && top === 0){ | ||
| //cover the situation where the window was fully scrolled faster than expand could keep up and locked to the top | ||
| requestAnimationFrame(this.expand); | ||
| } | ||
| this.dirty = false; | ||
| } | ||
| }; | ||
|
|
||
| Scroller.prototype._expand = function(){ | ||
| this.startPosition = Math.max(0, this.startPosition - this.minVisible); | ||
| this.sticky = false; | ||
| if(this.console){ | ||
| var scrollHeight = this.console.scrollHeight; | ||
| var scrollTop = this.console.scrollTop; | ||
|
|
||
| // do an inline scroll to avoid potential scroll interleaving | ||
| this.console.innerHTML = generateContent(this.lines, this.startPosition, this.lines.length, this.minVisible); | ||
| var newScrollHeight = this.console.scrollHeight; | ||
| this.console.scrollTop = scrollTop + newScrollHeight - scrollHeight; | ||
|
|
||
| this.dirty = false; | ||
| } | ||
| }; | ||
|
|
||
| Scroller.prototype._onScroll = function(){ | ||
| if(this.jumpToBottom){ | ||
| // do nothing, prepare to jump | ||
| return; | ||
| } | ||
| var height = this.console.offsetHeight; | ||
| var scrollHeight = this.console.scrollHeight; | ||
| var scrollTop = this.console.scrollTop; | ||
| if(this.sticky){ | ||
| if(scrollTop + height < scrollHeight - 30){ | ||
| this.sticky = false; | ||
| } | ||
| }else{ | ||
| if(scrollTop < 15 && this.startPosition > 0){ | ||
| this.expand(); | ||
| }else if(scrollTop + height > scrollHeight - 30){ | ||
| this.jumpToBottom = true; | ||
| this.sticky = true; | ||
| this.dirty = true; | ||
| } | ||
| } | ||
|
|
||
| if(this.dirty && !this.animateRequest){ | ||
| this.animateRequest = requestAnimationFrame(this.refresh); | ||
| } | ||
| }; | ||
|
|
||
| Scroller.prototype.setConsole = function(console){ | ||
| this.console = console; | ||
| }; | ||
|
|
||
| module.exports = Scroller; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,23 @@ | ||
| 'use strict'; | ||
|
|
||
| const React = require('react'); | ||
| const { createContainer } = require('sovereign'); | ||
|
|
||
| const Indicators = require('./indicators'); | ||
| const styles = require('./styles'); | ||
| const transmissionStore = require('../../src/stores/transmission'); | ||
|
|
||
| class TransmissionBar extends React.Component { | ||
|
|
||
| render() { | ||
| const { flashRx, flashTx } = this.props; | ||
| shouldComponentUpdate() { | ||
| return false; | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <div style={styles.bar}> | ||
| <Indicators flashRx={flashRx} flashTx={flashTx} /> | ||
| <Indicators /> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| module.exports = createContainer(TransmissionBar, { | ||
| getStores(){ | ||
| return { | ||
| deviceStore: transmissionStore | ||
| }; | ||
| }, | ||
|
|
||
| getPropsFromStores() { | ||
| return transmissionStore.getState(); | ||
| } | ||
| }); | ||
| module.exports = TransmissionBar; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ints here are just shortcuts to px styles, but this is fine