From 5e86b83eee8ae7395d2affde5692ef1b49b56bb6 Mon Sep 17 00:00:00 2001 From: Vincent Chan Date: Mon, 1 Aug 2022 12:41:51 +0800 Subject: [PATCH] feat: fromJson --- .../packages/flowy_editor/lib/operation/operation.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/app_flowy/packages/flowy_editor/lib/operation/operation.dart b/frontend/app_flowy/packages/flowy_editor/lib/operation/operation.dart index e4d2c1d8ed..d3b3144873 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/operation/operation.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/operation/operation.dart @@ -2,6 +2,16 @@ import 'package:flowy_editor/document/attributes.dart'; import 'package:flowy_editor/flowy_editor.dart'; abstract class Operation { + factory Operation.fromJson(Map map) { + String t = map["type"] as String; + if (t == "insert-operation") { + final path = map["path"] as List; + final value = Node.fromJson(map["value"]); + return InsertOperation(path: path, value: value); + } + + throw ArgumentError('unexpected type $t'); + } final Path path; Operation({required this.path}); Operation copyWithPath(Path path);