| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE.md file. | |
| 4 | |
| 5 // Should become auto-generated. | |
| 6 | |
| 7 library todomvc_presenter; | |
| 8 | |
| 9 import 'todomvc_service.dart'; | |
| 10 import 'todomvc_presenter_model.dart'; | |
| 11 | |
| 12 abstract class TodoMVCPresenter extends TodoMVCService { | |
| 13 | |
| 14 var _presentation = new Nil(); | |
| 15 var _eventManager = new EventManager(); | |
| 16 | |
| 17 // Construct a "presenter model" from the model. | |
| 18 Immutable render(Immutable previous); | |
| 19 | |
| 20 // Compare two "presenter models" to calculate a patch set for the host. | |
| 21 MyPatchSet diff(Immutable previous, Immutable current) { | |
| 22 var patchSet = new MyPatchSet(); | |
| 23 current.diff(previous, null, patchSet); | |
| 24 for (var patch in patchSet.patches) { | |
| 25 trace("{ path: ${patch.path}, content: ${patch.content} }"); | |
| 26 } | |
| 27 return patchSet; | |
| 28 } | |
| 29 | |
| 30 // Update the presentation and get the current patch set. | |
| 31 MyPatchSet update() { | |
| 32 var previous = _presentation; | |
| 33 _presentation = render(previous); | |
| 34 return diff(previous, _presentation); | |
| 35 } | |
| 36 | |
| 37 // Entry point for synchronizing with the host mirror. | |
| 38 void sync(PatchSetBuilder result) { | |
| 39 update().serialize(result, _eventManager); | |
| 40 } | |
| 41 | |
| 42 void reset() { | |
| 43 _presentation = new Nil(); | |
| 44 _eventManager.clear(); | |
| 45 } | |
| 46 | |
| 47 void dispatch(int eventHandlerId) { | |
| 48 _eventManager.call(eventHandlerId); | |
| 49 } | |
| 50 } | |
| OLD | NEW |