| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using Invercargill;
- using Invercargill.DataStructures;
- using InvercargillJson;
- using Statum;
- namespace ClankerSaddle {
- /**
- * Helpers for shaping Statum slot state. Because Statum's GObjectMapping
- * cannot serialise array/list fields, lists are built as a JsonArray and set
- * on a PropertyDictionary under a key, where stm-for-{x}-in can iterate them.
- */
- public class StateJson : Object {
- /**
- * Builds a JSON array element from a lot of GObject row models, mapping
- * each row via GObjectMapping. Use the result as a slot public-data value:
- * `dict["tasks"] = StateJson.list<TaskView>(rows);`
- */
- public static JsonElement list<T>(Lot<T> items) throws GLib.Error {
- var arr = new JsonArray();
- foreach (var item in items) {
- var props = GObjectMapping.to_properties((Object) item);
- arr.add(new JsonElement.from_properties(props));
- }
- return new JsonElement.from_elements(arr);
- }
- /** Same as {@link list} but accepts a Vala array. */
- public static JsonElement list_array<T>(T[] items) throws GLib.Error {
- var arr = new JsonArray();
- foreach (var item in items) {
- var props = GObjectMapping.to_properties((Object) item);
- arr.add(new JsonElement.from_properties(props));
- }
- return new JsonElement.from_elements(arr);
- }
- }
- }
|