Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 3866dad

Browse files
authored
Merge pull request #445 from lightninglabs/faster-logs
Faster logs
2 parents 4768a0d + 666ba2d commit 3866dad

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

src/component/list.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ export class List extends Component {
5656
ref={component => (this.list = component)}
5757
dataSource={this.dataSource}
5858
renderHeader={this.props.renderHeader}
59-
renderRow={data => {
60-
if (this.props.scrollToEnd) {
61-
setTimeout(() => this.list._scrollViewRef.scrollToEnd(), 50);
62-
}
63-
return this.props.renderItem(data);
64-
}}
59+
renderRow={this.props.renderItem}
6560
enableEmptySections={true}
6661
/>
6762
);
@@ -72,7 +67,6 @@ List.propTypes = {
7267
data: PropTypes.array.isRequired,
7368
renderHeader: PropTypes.func,
7469
renderItem: PropTypes.func.isRequired,
75-
scrollToEnd: PropTypes.bool,
7670
};
7771

7872
//

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports.PREFIX_URI = `${prefixName}:`;
1313

1414
module.exports.DEFAULT_ROUTE = 'Welcome';
1515
module.exports.MIN_PASSWORD_LENGTH = 8;
16-
module.exports.MAX_LOG_LENGTH = 30;
16+
module.exports.MAX_LOG_LENGTH = 100;
1717

1818
module.exports.UNITS = {
1919
sat: { display: 'SAT', displayLong: 'Satoshi', denominator: 1 },

src/view/cli.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
import React from 'react';
2-
import { StyleSheet } from 'react-native';
1+
import React, { Component } from 'react';
2+
import { ScrollView, StyleSheet } from 'react-native';
33
import { observer } from 'mobx-react';
44
import PropTypes from 'prop-types';
55
import Background from '../component/background';
66
import { Header, Title } from '../component/header';
77
import Text from '../component/text';
8-
import { List, ListContent } from '../component/list';
98
import { Button, BackButton } from '../component/button';
109
import { color, font } from '../component/style';
1110

1211
//
1312
// CLI View
1413
//
1514

15+
const styles = StyleSheet.create({
16+
header: {
17+
marginBottom: 1, // display separator above output background color
18+
},
19+
});
20+
1621
const CLIView = ({ store, nav }) => (
1722
<Background color={color.blackDark}>
18-
<Header separator>
23+
<Header separator style={styles.header}>
1924
<BackButton onPress={() => nav.goSettings()} />
2025
<Title title="Logs" />
2126
<Button disabled onPress={() => {}} />
2227
</Header>
23-
<Background color={color.cliBackground}>
24-
<ListContent>
25-
<List
26-
data={store.logs.slice()}
27-
renderItem={text => <LogItem text={text} />}
28-
scrollToEnd={true}
29-
/>
30-
</ListContent>
31-
</Background>
28+
<LogOutput logs={store.logs.slice()} />
3229
</Background>
3330
);
3431

@@ -37,17 +34,46 @@ CLIView.propTypes = {
3734
nav: PropTypes.object.isRequired,
3835
};
3936

40-
const iStyles = StyleSheet.create({
37+
//
38+
// Log Output
39+
//
40+
41+
const logStyles = StyleSheet.create({
42+
content: {
43+
flexGrow: 1,
44+
backgroundColor: color.cliBackground,
45+
paddingTop: 25,
46+
paddingBottom: 25,
47+
paddingLeft: 50,
48+
paddingRight: 50,
49+
},
4150
text: {
42-
textAlign: 'left',
4351
fontSize: font.sizeS,
4452
},
4553
});
4654

47-
const LogItem = ({ text }) => <Text style={iStyles.text}>{text}</Text>;
55+
class LogOutput extends Component {
56+
constructor(props) {
57+
super(props);
58+
this._ref = React.createRef();
59+
}
60+
61+
get printLogs() {
62+
setTimeout(() => this._ref.current.scrollToEnd(), 50);
63+
return this.props.logs.map(l => l.replace(/\s+$/, '')).join('\n');
64+
}
65+
66+
render() {
67+
return (
68+
<ScrollView ref={this._ref} contentContainerStyle={logStyles.content}>
69+
<Text style={logStyles.text}>{this.printLogs}</Text>
70+
</ScrollView>
71+
);
72+
}
73+
}
4874

49-
LogItem.propTypes = {
50-
text: PropTypes.string,
75+
LogOutput.propTypes = {
76+
logs: PropTypes.array.isRequired,
5177
};
5278

5379
export default observer(CLIView);

test/unit/action/log.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ describe('Action Logs Unit Tests', () => {
5151

5252
describe('constructor()', () => {
5353
it('should keep logs trimmed and keep the tail of the logs', () => {
54-
for (var i = 0; i < 31; i++) {
54+
for (var i = 0; i < 101; i++) {
5555
ipcRendererStub.emit('logs', 'some-event', i.toString());
5656
}
57-
expect(store.logs.length, 'to equal', 30);
57+
expect(store.logs.length, 'to equal', 100);
5858
expect(store.logs[0], 'to equal', '1');
59-
expect(store.logs[29], 'to equal', '30');
59+
expect(store.logs[99], 'to equal', '100');
6060
});
6161
});
6262
});

0 commit comments

Comments
 (0)