Async operations in returning event handlers

Hi! I’m using Webix for quite some time now and really like how much it speeds up the development process. However I came across an issue which I don’t know how to solve without patching Webix itself. My application requires client-server object syncronization via custom bidirectional CRUD protocol(something like stripped down version of Meteor.js) and it seemed natural to use DataStore as a syncronization unit with server communication happening in event callbacks(e.g. send “create” command from “onBeforeAdd” handler, wait until server responds with “created” and only then add object to local DataStore). But quick look through webix_debug.js revealed that it’s not possible - event callbacks should return immediately. I’m thinking about pathching DataStore in the way it returns Promise object instead of true/false and AFAIU it won’t cause a lot of problems(except the “add” method, which returns new item id and hence all its occurences in other parts of code should be also refactored to handle promises). What do you think about this approach? Or could you suggest a better/conventional one? Thanks in advance!

You still can use your original idea with existing event handlers

  • add handler to onBeforeAdd
  • initiate the remote call from the event handler
  • return false from event handler => prevent real data adding
  • on remote callback set some global flag and call data.add again
  • code in onBeforeAdd handler must return true when global flag set

With above logic, after adding new item, component will send signal to the remote but will not add the item. When callback received, code will really add item to the component.

Solution with promises looks too complicated