From 3e2be6b7e9f0170d3606403aa13f86156d9d83be Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 19 Oct 2022 19:34:10 +0300 Subject: [PATCH] notes asnd docs... Signed-off-by: Alex A. Naanou --- pwiki/store/base.js | 73 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 5270f26..f568293 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -28,12 +28,58 @@ var pwpath = require('../path') // -// XXX need support for: -// 'update', , -// 'remove', +// +// makeIndexed(, [, ]) +// -> +// +// Get merged data (cached) +// () +// ('get') +// -> +// +// Get local data (uncached)... +// ('local') +// -> +// +// Clear cache... +// ('clear') +// -> +// +// Reset cache (clear then get)... +// ('reset') +// -> +// +// Run custom action... +// (), ...) +// -> +// +// +// +// Special methods: +// +// Special method to generate local ... +// .____() +// -> +// +// Merge local data with other sources... +// .___merge__() +// -> +// +// Handle custom action... +// ._____(. ...) +// -> +// +// +// +// Special attributes: +// +// Cached data... +// .___cache / . +// // var makeIndexed = function(name, generate, options={}){ + // XXX revise default... var cache = !!options.attr ? name : `__${name}_cache` @@ -72,11 +118,12 @@ function(name, generate, options={}){ this[cache] : meth.call(this, 'reset') return _await(this, this[cache] = - (action in options + // NOTE: this[action_meth] will fully shadow options[action]... + action_meth in this ? + this[action_meth](cur, ...args) + : (action in options && typeof(options[action]) == 'function') ? options[action].call(this, cur, ...args) - : action_meth in this ? - this[action_meth](cur, ...args) : cur) } // get... return _await(this, @@ -103,6 +150,7 @@ function(name, generate, options={}){ var indexTest = module.indexTest = { + // XXX rename??? get indexi(){ var that = this return object.deepKeys(this) @@ -126,7 +174,7 @@ module.indexTest = // moo: makeIndexed('moo', () => 123), - _foo_index: makeIndexed('foo', () => 123, { + foo_index: makeIndexed('foo', () => 123, { attr: true, add: function(cur, val){ return cur + val }, @@ -136,9 +184,16 @@ module.indexTest = return cur + val }, boo: makeIndexed('boo', () => 123), - __amoo_add__: async function(cur, val){ + __soo_add__: async function(cur, val){ return await cur + val }, - amoo: makeIndexed('amoo', async () => 123), + __soo: makeIndexed('soo', async () => 123), + get soo(){ + return this.__soo() } + + // XXX need a way to link indexes... + // Ex: + // sum -> soo + boo + foo + moo + // ...changing any of the summed values should drop cache of sum }