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 #include "todomvc_presenter.h" | |
6 | |
7 void VoidCallback(void*) {} | |
8 | |
9 void TodoMVCPresenter::createItem(char* title) { | |
10 int length = 0; | |
11 while (title[length] != '\0') ++length; | |
12 int size = 56 + BoxedStringBuilder::kSize + length; | |
13 MessageBuilder builder(size); | |
14 BoxedStringBuilder box = builder.initRoot<BoxedStringBuilder>(); | |
15 box.setStr(title); | |
16 TodoMVCService::createItemAsync(box, VoidCallback, NULL); | |
17 } | |
18 | |
19 void TodoMVCPresenter::clearItems() { | |
20 TodoMVCService::clearItemsAsync(VoidCallback, NULL); | |
21 } | |
22 | |
23 void TodoMVCPresenter::dispatch(event id) { | |
24 TodoMVCService::dispatchAsync(id, VoidCallback, NULL); | |
25 } | |
26 | |
27 void TodoMVCPresenter::sync() { | |
28 // Assuming a synchronous call will flush outstanding asynchronous calls. | |
29 applyPatches(TodoMVCService::sync()); | |
30 } | |
31 | |
32 void TodoMVCPresenter::applyPatches(const PatchSet& patch_set) { | |
33 List<Patch> patches = patch_set.getPatches(); | |
34 for (int i = 0; i < patches.length(); ++i) { | |
35 applyPatch(patches[i]); | |
36 } | |
37 } | |
38 | |
39 void TodoMVCPresenter::applyPatch(const Patch& patch) { | |
40 enterPatch(); | |
41 List<uint8_t> path = patch.getPath(); | |
42 for (int i = 0; i < path.length(); ++i) { | |
43 switch (path[i]) { | |
44 case TAG_CONS_FST: enterConsFst(); break; | |
45 case TAG_CONS_SND: enterConsSnd(); break; | |
46 case TAG_CONS_DELETE_EVENT: enterConsDeleteEvent(); break; | |
47 case TAG_CONS_COMPLETE_EVENT: enterConsCompleteEvent(); break; | |
48 case TAG_CONS_UNCOMPLETE_EVENT: enterConsUncompleteEvent(); break; | |
49 default: abort(); | |
50 } | |
51 } | |
52 updateNode(patch.getContent()); | |
53 } | |
OLD | NEW |