Bug 1363680 - Move the repeat information outside of the message type. r=Honza

MozReview-Commit-ID: J7IJgEYnLhn

--HG--
extra : rebase_source : 2d216915e9e3c59b9d128f4484b340d902bc9c86
This commit is contained in:
Nicolas Chevobbe 2017-06-05 14:15:09 +02:00
Родитель a95523e2a5
Коммит 568a26e351
7 изменённых файлов: 35 добавлений и 10 удалений

Просмотреть файл

@ -15,6 +15,7 @@ const {
getAllMessagesUiById,
getAllMessagesTableDataById,
getVisibleMessages,
getAllRepeatById,
} = require("devtools/client/webconsole/new-console-output/selectors/messages");
const MessageContainer = createFactory(require("devtools/client/webconsole/new-console-output/components/message-container").MessageContainer);
@ -32,6 +33,7 @@ const ConsoleOutput = createClass({
dispatch: PropTypes.func.isRequired,
timestampsVisible: PropTypes.bool,
messagesTableData: PropTypes.object.isRequired,
messagesRepeat: PropTypes.object.isRequired,
visibleMessages: PropTypes.array.isRequired,
},
@ -75,6 +77,7 @@ const ConsoleOutput = createClass({
visibleMessages,
messagesUi,
messagesTableData,
messagesRepeat,
serviceContainer,
timestampsVisible,
} = this.props;
@ -90,6 +93,7 @@ const ConsoleOutput = createClass({
tableData: messagesTableData.get(message.id),
indent: message.indent,
timestampsVisible,
repeat: messagesRepeat[message.id]
})
);
});
@ -123,6 +127,7 @@ function mapStateToProps(state, props) {
visibleMessages: getVisibleMessages(state),
messagesUi: getAllMessagesUiById(state),
messagesTableData: getAllMessagesTableDataById(state),
messagesRepeat: getAllRepeatById(state),
timestampsVisible: state.ui.timestampsVisible,
};
}

Просмотреть файл

@ -37,6 +37,7 @@ const MessageContainer = createClass({
indent: PropTypes.number.isRequired,
tableData: PropTypes.object,
timestampsVisible: PropTypes.bool.isRequired,
repeat: PropTypes.object,
},
getDefaultProps: function () {
@ -47,7 +48,7 @@ const MessageContainer = createClass({
},
shouldComponentUpdate(nextProps, nextState) {
const repeatChanged = this.props.message.repeat !== nextProps.message.repeat;
const repeatChanged = this.props.repeat !== nextProps.repeat;
const openChanged = this.props.open !== nextProps.open;
const tableDataChanged = this.props.tableData !== nextProps.tableData;
const responseChanged = this.props.message.response !== nextProps.message.response;

Просмотреть файл

@ -42,13 +42,13 @@ function ConsoleApiCall(props) {
serviceContainer,
indent,
timestampsVisible,
repeat,
} = props;
const {
id: messageId,
source,
type,
level,
repeat,
stacktrace,
frame,
timeStamp,

Просмотреть файл

@ -35,6 +35,8 @@ const MessageState = Immutable.Record({
// List of removed messages is used to release related (parameters) actors.
// This array is not supposed to be consumed by any UI component.
removedMessages: [],
// Map of the form {messageId : numberOfRepeat}
repeatById: {}
});
function messages(state = new MessageState(), action, filtersState, prefsState) {
@ -44,6 +46,7 @@ function messages(state = new MessageState(), action, filtersState, prefsState)
messagesTableDataById,
groupsById,
currentGroup,
repeatById,
visibleMessages,
} = state;
@ -65,13 +68,15 @@ function messages(state = new MessageState(), action, filtersState, prefsState)
if (newMessage.allowRepeating && messagesById.size > 0) {
let lastMessage = messagesById.last();
if (lastMessage.repeatId === newMessage.repeatId) {
if (
lastMessage.repeatId === newMessage.repeatId
&& lastMessage.groupId === currentGroup
) {
return state.set(
"messagesById",
messagesById.set(
lastMessage.id,
lastMessage.set("repeat", lastMessage.repeat + 1)
)
"repeatById",
Object.assign({}, repeatById, {
[lastMessage.id]: (repeatById[lastMessage.id] || 1) + 1
})
);
}
}
@ -321,6 +326,17 @@ function limitTopLevelMessageCount(state, record, logLimit) {
record.set("groupsById", record.groupsById.withMutations(cleanUpCollection));
}
if (Object.keys(record.repeatById).includes(removedMessagesId)) {
record.set("repeatById",
[...Object.entries(record.repeatById)].reduce((res, [id, repeat]) => {
if (!isInRemovedId(id)) {
res[id] = repeat;
}
return res;
}, {})
);
}
return record;
}

Просмотреть файл

@ -33,6 +33,10 @@ function getVisibleMessages(state) {
return state.messages.visibleMessages.map(id => getMessage(state, id));
}
function getAllRepeatById(state) {
return state.messages.repeatById;
}
module.exports = {
getMessage,
getAllMessagesById,
@ -41,4 +45,5 @@ module.exports = {
getAllGroupsById,
getCurrentGroup,
getVisibleMessages,
getAllRepeatById,
};

Просмотреть файл

@ -33,7 +33,6 @@ exports.ConsoleMessage = Immutable.Record({
level: null,
messageText: null,
parameters: null,
repeat: 1,
repeatId: null,
stacktrace: null,
frame: null,

Просмотреть файл

@ -237,7 +237,6 @@ function transformPacket(packet) {
// Helpers
function getRepeatId(message) {
message = message.toJS();
message.repeat = null;
message.timeStamp = null;
return JSON.stringify(message);
}