mobx-state-tree: Fault tolerance of Medel

Question

  • I’ve checked documentation and searched for existing issues
  • I tried the spectrum channel
  • is there a way to check if the object param passed to the model.create function is valid or not ?
    **example (see codeSandbox link) ** :
    const store = modelStore.create({ appName : 'testApp', todos: [ { title : 'Todo title, checked : false }, ] })
  • when this Create function generate an exception, is there a way to find the sub_Model responsible of the exception. so instead of generate an exception just not render the responsible component that use the wrong part of the model

[Details]

with this code sandbox example i have an action resetTodos in TodoStore.js (model) with array as param. if i use it with a valid Todo array (Todo is the model of a single Todo) it works as expected. but when for example a single todo element in the array is wrong (e.g title : true instead of title : "new Title') the whole App breaks so i want to render the App, just check out the wrong Todo component and not render it

wanted behaviour

image

current behaviour

image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

You can always validate a model first by doing model.is(snapshot) instead of .create