From 56514d7e172cb12a7c1c9b104110f8c7a03d58d7 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 24 Jul 2017 15:10:15 +0200 Subject: [PATCH] add val api --- www/todo/todo.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/www/todo/todo.js b/www/todo/todo.js index 8d1cac86f..654a56948 100644 --- a/www/todo/todo.js +++ b/www/todo/todo.js @@ -25,6 +25,16 @@ define([ } */ + var val = function (proxy, id, k, v) { + var el = proxy.data[id]; + if (!el) { + throw new Error('expected an element'); + } + if (typeof(v) === 'function') { el[k] = v(el[k]); } + else { el[k] = v; } + return el[k]; + }; + var initialize = function (proxy) { // run migration if (typeof(proxy.data) !== 'object') { proxy.data = {}; } @@ -56,6 +66,9 @@ define([ var api = {}; initialize(proxy); + api.val = function (id, k, v) { + return val(proxy, id, k, v); + }; api.add = function (id, obj) { return add(proxy, id, obj); };