From 0ac9380a900e00f5b75261e1eda1bbecefb66690 Mon Sep 17 00:00:00 2001 From: CSDUMMI <31551856+CSDUMMI@users.noreply.github.com> Date: Sat, 2 Oct 2021 23:38:22 +0200 Subject: [PATCH] Example for how the validationFn could work. I wanted to give people an example in code of my idea for validation functions as an additional and more powerful custom validation & access control mechanism than Access Controllers are currently. --- src/KeyValueIndex.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/KeyValueIndex.js b/src/KeyValueIndex.js index a7520bd..25f68b8 100644 --- a/src/KeyValueIndex.js +++ b/src/KeyValueIndex.js @@ -1,8 +1,10 @@ 'use strict' class KeyValueIndex { - constructor() { + constructor(validationFn, store) { this._index = {} + this._validationFn = validationFn + this._store = store } get(key) { @@ -14,7 +16,7 @@ class KeyValueIndex { .slice() .reverse() .reduce((handled, item) => { - if(!handled.includes(item.payload.key)) { + if(!handled.includes(item.payload.key) && this._validationFn(item, store)) { handled.push(item.payload.key) if(item.payload.op === 'PUT') { this._index[item.payload.key] = item.payload.value