fconsole
fconsole copied to clipboard
[Discussions] Adding a new log before emitting an event
Content
_addRawLog(Log log) {
...
if (log.type == LogType.error) {
_hasError = true;
_emit(FlowLogEvent.error, this);
} else {
_emit(FlowLogEvent.log, this);
}
this.logs!.add(log);
...
}
The 'newLog' event will be emitted before it is added to the logs, which means the listener has no way to know the content of the latest log.
I think it's better to move the _emit
part after this.logs!.add(log)
, so the listener is able to access the latest log by using logs[logs.length - 1]
Also, it is possible to change List<Log>? logs
to List<Log> logs
by giving a default []
, so we don't need to do null-check elsewhere.