From fdac337a0479a5f74dfe4c33ea733c20db6b638a Mon Sep 17 00:00:00 2001 From: "J.R. Patten" Date: Fri, 1 Aug 2014 16:05:39 -0600 Subject: [PATCH] Add nested property setting --- lib/adapter.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/adapter.js b/lib/adapter.js index 2dec92b..2ff1dc1 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -46,7 +46,22 @@ Adapter.prototype.unsubscribeAll = function() { Adapter.prototype.set = function(prop, val) { var obj = this.obj; + var parts = prop.split('.') + var part = parts.shift() if (!obj) return; + + // split property on '.' access + // and dig into the object + while (parts.length) { + // create the nested property if it doesn't exist + if (obj[part] === undefined) { + obj[part] = {}; + } + + obj = obj[part]; + part = prop = parts.shift(); + }; + if ('function' == typeof obj[prop]) { obj[prop](val); }