Skip to content
This repository was archived by the owner on Aug 13, 2018. It is now read-only.

Commit 1b981f6

Browse files
committed
Merge pull request #42 from esphen/issue41
Clear connection ID filter list on reload
2 parents 0aa774d + 81fed13 commit 1b981f6

File tree

5 files changed

+29
-31
lines changed

5 files changed

+29
-31
lines changed

data/actions/frames.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const types = {
1111
FILTER_FRAMES: "FILTER_FRAMES",
1212
}
1313

14-
function clear() {
15-
return { type: types.CLEAR };
14+
function clear(options) {
15+
return { type: types.CLEAR, options };
1616
}
1717

1818
function addFrame(frame) {

data/components/connection-filter.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ var ConnectionFilter = React.createClass({
2525

2626
displayName: "ConnectionFilter",
2727

28-
getInitialState() {
29-
return {
30-
uniqueConnections: []
31-
};
32-
},
33-
3428
handleChange(e) {
3529
const { value } = e.target;
3630
const currentFilter = this.props.frames.filter;
@@ -44,23 +38,8 @@ var ConnectionFilter = React.createClass({
4438
));
4539
},
4640

47-
// When the platform API supports it, this should be replaced
48-
// with some API call listing only the current connections on
49-
// the page.
50-
componentWillReceiveProps({ frames }) {
51-
frames.frames.forEach(frame => {
52-
const { uniqueConnections } = this.state;
53-
54-
if (!uniqueConnections.includes(frame.webSocketSerialID)) {
55-
this.setState({
56-
uniqueConnections: [...uniqueConnections, frame.webSocketSerialID]
57-
});
58-
}
59-
})
60-
},
61-
6241
render() {
63-
const { uniqueConnections } = this.state;
42+
const { uniqueConnections } = this.props.frames;
6443
return (
6544
uniqueConnections.length > 1 ?
6645
select({

data/reducers/frames.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function getInitialState() {
1515
return {
1616
frames: [],
1717
selection: null,
18+
uniqueConnections: [],
1819
filter: {
1920
text: "",
2021
frames: null
@@ -40,7 +41,7 @@ function frames(state = getInitialState(), action) {
4041
return filterFrames(state, action.filter);
4142

4243
case types.CLEAR:
43-
return clear(state);
44+
return clear(state, action.options);
4445

4546
case selectionTypes.SELECT_FRAME:
4647
return selectFrame(state, action.frame);
@@ -68,6 +69,7 @@ function addFrames(state, newFrames) {
6869
}
6970

7071
var { totalSize, frameCount, startTime, endTime } = state.summary;
72+
var uniqueConnections = state.uniqueConnections;
7173

7274
// Update summary info
7375
newFrames.forEach(frame => {
@@ -78,14 +80,24 @@ function addFrames(state, newFrames) {
7880
endTime = data.timeStamp;
7981
}
8082

83+
// Update uniqueConnections.
84+
//
85+
// When the platform API supports it, this should be replaced
86+
// with some API call listing only the current connections on
87+
// the page.
88+
if (!uniqueConnections.includes(frame.webSocketSerialID)) {
89+
uniqueConnections.push(frame.webSocketSerialID);
90+
}
91+
8192
if (frame.type == "frame") {
8293
frameCount++;
8394
}
8495
});
8596

8697
// Return new state
8798
var newState = Object.assign({}, state, {
88-
frames: frames,
99+
frames,
100+
uniqueConnections,
89101
summary: {
90102
totalSize: totalSize,
91103
startTime: startTime,
@@ -160,11 +172,17 @@ function filterFrames(state, filter) {
160172
});
161173
}
162174

163-
function clear(state) {
175+
function clear(state, options = {}) {
164176
// All data is cleared except for the current filters.
165177
var newState = getInitialState();
166178
newState.filter.text = state.filter.text;
167-
newState.filter.webSocketSerialID = state.filter.webSocketSerialID;
179+
180+
// Allow clearing on page reload
181+
if (options.resetIDfilter !== true) {
182+
newState.filter.webSocketSerialID = state.filter.webSocketSerialID;
183+
newState.uniqueConnections = state.uniqueConnections;
184+
}
185+
168186
return newState;
169187
}
170188

data/view.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ var WebSocketsView = createView(PanelView,
6060

6161
// Chrome Messages
6262

63-
removeFrames: function() {
64-
store.dispatch(clear());
63+
tabNavigated: function() {
64+
// Clear on reload, and force ID filter reset
65+
store.dispatch(clear({ resetIDfilter: true }));
6566
},
6667

6768
// nsIWebSocketEventService events

lib/wsm-panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const WsmPanel = Class(
183183
},
184184

185185
onTabNavigated: function() {
186-
this.postContentMessage("removeFrames");
186+
this.postContentMessage("tabNavigated");
187187
},
188188

189189
// nsIWebSocketEventService events

0 commit comments

Comments
 (0)