-
Notifications
You must be signed in to change notification settings - Fork 0
Positional element transactions
User made positional element's rules could throw exceptions if the code is complex and not well tested, this page explains what happens in that case.
Positional rules have a incomplete transactional behaviour:
- html changes are transactional if made by using provided methods and rules, such as the export rule, not if done by native javascript code.
- model data changes are transactional only if made through "this.model" built-in variabile.
any change will be synchronized and kept coherent the environment variables. eg: if you increase the x coordinate of relative position by 10 (using setRelativePos), graphPosition.x will be increased by 10 too. the actual draw of the changes will only take place after the script successfull end. This means if you measure the html node size through native javascript functions, it will be the same even after setWidth(). So please use synchronized built-in variables instead.
-
actions involving html (this.node) and attributes (this.a). this will be improved in future to make safe at least the html nodes marked as "synchronized" when collaborative editing will be implemented. NB: _Export commands are safe even when they edit the html, because they overwrite the html or attribute values only at the end of execution and only if no error occurred.
-
actions involving this.model.unsafe
-
actions involving this.model.pendingChanges or this.model.subChanges, those variables are not meant for direct usage at all.
-
invalid parameters in buffered this.model "set" function calls. If there are 5 buffered calls and the 3° throws a parameter exception: 4° and 5° will not be executed, 1° and 2° will not be rollbacked.
all "get" functions behave normally and in a safe way.
all "set" functions will return undefined without being executed, they are buffered and will be executed only at the end of the user script, if no errors occurred.
this.setWidth(100);
let a = this.model.getUpperbound();
this.model.setUpperbound(a+1);
if (a == this.model.getUpperbound()) this.model.setName( 'newClassName' );
a += a[0];
this.model.setLowerbound(0);
the following relevant event occurs:
getUpperbound() will be executed returning a value
setUpperbound() will be buffered without executing
since setUpperbound has not been executed yet, the if condition is true and setName() will be buffered without executing.
a += a[0] will throw an error, since "a" is a number, the execution of the user script stops here.
the builtin-code will trash the function call buffer preventing the scheduled execution of setName()
the width change will be rollbacked.
example 2:
this.setWidth(100);
this.model.setName( 'newClassName' );
this.model.setUpperbound(new Array(2,5,7));
this.model.setLowerbound(0);
this time the eser script reaches the end and the call buffer contains setName(), setUpperbound(), setLowerbound()
the buffer manager will execute setName() successfully
the buffer manager will try to execute setUpperbound() resulting in exception for invalid parameter.
the buffer manager will remove setLowerbound from buffer without executing.
the width change will rollback.
the classname changes will not be rollbacked.