google drive realtime api - How to maintain UI state across model changes? -


i have collaborativelist of objects have state of being selected in ui. 1 action user can take results in 1 object being removed , number of objects being added in place. have handlers valuesremoved , valuesadded events discard , add new views respectively. best way set selection state of newly added ui elements if old 1 selected?

i set flag on controlling class before making model changes checked in valuesaddedevent handler, won't allow me maintain selection state on undo/redo of modification. undo/redo doesn't appear adopt compound operation name list of change caused original events can't check either.

test('compound operation names in undo', function() {   doc.getmodel().begincompoundoperation('a name');   doc.getmodel().getroot().set('key','value');   doc.getmodel().endcompoundoperation();   var vc = function(event) {     deepequal(event.compoundoperationnames, ['a name']);   };   doc.getmodel().getroot().addeventlistener(gapi.drive.realtime.eventtype.value_changed, vc);   doc.getmodel().undo();   doc.getmodel().getroot().removeeventlistener(gapi.drive.realtime.eventtype.value_changed, vc); }); 

test fails expected: ['a name'], actual: []

you track selected range in model using indexreferences. have side benefit of allowing display information collaborators, if makes sense in application.

if don't want persist it, think should able determine when in situation looking @ set of changes + current selection.

if have objectchangedlistener on list, event contains of changes within compound operation. if have set of changes matches behavior, , index referenced 1 selected know in situation , can act according.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -