Snapshot validation #1940
-
Is there some best way to validate snapshot for a model? I need to check snapshot for const Node = types.union(
{ dispatcher: (snapshot) => 'message' in snapshot ? Message : Form },
Form,
Message
); I don't want to check properties in snapshot. I have an idea to create model instance with snapshot and check if error will be throw. May be there is best practice for this case? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @KislyakovDS! The You could e.g. do what the Ignite boilerplate does and try to instantiate a model in a |
Beta Was this translation helpful? Give feedback.
Hi @KislyakovDS!
The
dispatcher
option isn't really a validator, but rather a function to help determine what type of model the snapshot actually represents. I don't think you will be able to skip this if you have aunion
with two custom models.You could e.g. do what the Ignite boilerplate does and try to instantiate a model in a
try
/catch
, and have some fallback behavior if an error is thrown, but again I don't think this will help with determining the type of the union.