replaceDataFrom method

  1. @override
void replaceDataFrom(
  1. SimpleAppState other, {
  2. bool notifyListeners = true,
})
override

(en) For operations such as Undo, the current listeners are retained and only the data is replaced. The data is deep copied. After that, notifications are sent to all UI listeners in a batch process to update. In other words, the screen the user currently has open is automatically updated. Note that this operation deep copies the data to support Undo and Redo. If any data cannot be deep copied, a runtime error will be thrown.

(ja) Undo操作などで、現在のリスナを保持したままデータだけを入れ替えます。 その後、更新のために全てのUIリスナにバッチ処理で通知が送られます。 つまり、ユーザーが現在開いている画面に関して自動更新が行われます。 Undo、Redoへの対応のため、この操作ではデータがディープコピーされることに 注意してください。 ディープコピーできないデータがある場合は実行時エラーがスローされます。

  • other : Source data to deep copy.
  • notifyListeners : If false, this method will not notify listeners, which is useful if you need to do additional work after loading the state but before notifying the UI.

Implementation

@override
void replaceDataFrom(SimpleAppState other, {bool notifyListeners = true}) {
  if (other is! RefAppState) {
    throw StateError("The other param type is only supports RefAppState");
  }
  _data
    ..clear()
    ..addAll(UtilCopy.deepCopyJsonableOrClonableFile(other._data));
  if (notifyListeners) {
    notifyAll(); // 今いる listener に通知
  }
}