aberdeen 0.0.8 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- let e,t=new Set;function r(e){t.size||setTimeout(i,0),t.add(e)}function i(){let e;Array.from?e=Array.from(t):(e=[],t.forEach(t=>e.push(t))),e.sort((e,t)=>e.queueOrder-t.queueOrder);for(let r of e){t.delete(r);let e=t.size;if(r.queueRun(),t.size!==e)return i()}}export function sortKeyToString(e){return e instanceof Array?e.map(t).join(""):t(e);function t(e){if("string"==typeof e)return e+"";{let t=function(e,t){let r="";for(;e>0;)r+=String.fromCharCode(t?65535-e%65533:2+e%65533),e=Math.floor(e/65533);return r}(Math.abs(Math.round(e)),e<0);return String.fromCharCode(128+(e>0?t.length:-t.length))+t}}}class n{constructor(e,t,r){this.cleaners=[],this.isDead=!1,this.parentElement=e,this.precedingSibling=t,this.queueOrder=r}findPrecedingNode(){let e=this.precedingSibling;for(;e;){if(e instanceof Node)return e;let t=e.findLastNode();if(t)return t;e=e.precedingSibling}}findLastNode(){return this.lastChild instanceof Node?this.lastChild:this.lastChild instanceof n?this.lastChild.findLastNode()||this.lastChild.findPrecedingNode():void 0}addNode(e){let t=this.findLastNode()||this.findPrecedingNode();this.parentElement.insertBefore(e,t?t.nextSibling:this.parentElement.firstChild),this.lastChild=e}remove(){let e=this.findLastNode();if(e){let t=this.findPrecedingNode();for(;e!==t;){if(!e)return v(1);let t=e.previousSibling||void 0;this.parentElement.removeChild(e),e=t}}this.lastChild=void 0,this._clean()}_clean(){this.isDead=!0;for(let e of this.cleaners)e._clean(this)}onChange(e,t,i,n){r(this)}}class s extends n{constructor(e,t,r,i){super(e,t,r),this.renderer=i}queueRun(){e&&v(2),this.isDead||(this.remove(),this.isDead=!1,this.update())}update(){let t=e;e=this;try{this.renderer()}catch(e){w(e)}e=t}}class o extends n{constructor(e,t,r,i,n,s){super(e,t,r),this.byPosition=[],this.byIndex=new Map,this.newIndexes=new Set,this.removedIndexes=new Set,this.collection=i,this.renderer=n,this.makeSortKey=s}onChange(e,t,i,n){void 0===n?this.removedIndexes.has(t)?this.removedIndexes.delete(t):(this.newIndexes.add(t),r(this)):void 0===i&&(this.newIndexes.has(t)?this.newIndexes.delete(t):(this.removedIndexes.add(t),r(this)))}queueRun(){if(this.isDead)return;let e=this.removedIndexes;this.removedIndexes=new Set,e.forEach(e=>{this.removeChild(e)}),e=this.newIndexes,this.newIndexes=new Set,e.forEach(e=>{this.addChild(e)})}_clean(){super._clean(),this.collection.observers.delete(this);for(let e of this.byPosition)e._clean();this.byPosition.length=0,this.byIndex.clear()}renderInitial(){if(!e)return v(3);let t=e;this.collection.iterateIndexes(this),e=t}addChild(e){let t=new a(this.parentElement,void 0,this.queueOrder+1,this,e);this.byIndex.set(e,t),t.update()}removeChild(e){let t=this.byIndex.get(e);if(!t)return v(6);this.byIndex.delete(e),this.removeFromPosition(t),t.remove()}findPosition(e){let t=this.byPosition,r=0,i=this.byPosition.length;if(!i||e>t[i-1].sortStr)return i;for(;r<i;){let n=r+i>>1;t[n].sortStr<e?r=n+1:i=n}return r}insertAtPosition(e){let t=this.findPosition(e.sortStr);this.byPosition.splice(t,0,e),e.precedingSibling=t>0?this.byPosition[t-1]:this.precedingSibling,t+1<this.byPosition.length?this.byPosition[t+1].precedingSibling=e:this.lastChild=e}removeFromPosition(e){let t=this.findPosition(e.sortStr);for(;;){if(this.byPosition[t]===e)return this.byPosition.splice(t,1),void(t<this.byPosition.length?this.byPosition[t].precedingSibling=t>0?this.byPosition[t-1]:this.precedingSibling:this.lastChild=this.byPosition.length?this.byPosition[this.byPosition.length-1]:void 0);if(++t>=this.byPosition.length||this.byPosition[t].sortStr!==e.sortStr)return v(5)}}}class a extends n{constructor(e,t,r,i,n){super(e,t,r),this.sortStr="",this.parent=i,this.itemIndex=n}queueRun(){e&&v(4),this.isDead||(this.remove(),this.isDead=!1,this.update())}update(){let t=e;e=this;let r,i=new Store(this.parent.collection,this.itemIndex);try{r=this.parent.makeSortKey(i)}catch(e){w(e)}let n=this.sortStr,s=null==r?"":sortKeyToString(r);if(""!==n&&n!==s&&this.parent.removeFromPosition(this),this.sortStr=s,""!==s){s!==n&&this.parent.insertAtPosition(this);try{this.parent.renderer(i)}catch(e){w(e)}}e=t}}const h={};class d{constructor(){this.observers=new Map}addObserver(e,t){t=t;let r=this.observers.get(e);if(r){if(r.has(t))return!1;r.add(t)}else this.observers.set(e,new Set([t]));return!0}removeObserver(e,t){this.observers.get(e).delete(t)}emitChange(e,t,r){let i=this.observers.get(e);i&&i.forEach(i=>i.onChange(this,e,t,r)),i=this.observers.get(h),i&&i.forEach(i=>i.onChange(this,e,t,r))}_clean(e){this.removeObserver(h,e)}setIndex(e,t,r){const i=this.rawGet(e);if(!(i instanceof d)||t instanceof Store||!i.merge(t,r)){let r=Store._valueToData(t);r!==i&&(this.rawSet(e,r),this.emitChange(e,r,i))}}}class l extends d{constructor(){super(...arguments),this.data=[]}getType(){return"array"}getRecursive(t){e&&this.addObserver(h,e)&&e.cleaners.push(this);let r=[];for(let e=0;e<this.data.length;e++){let i=this.data[e];r.push(i instanceof d?t?i.getRecursive(t-1):new Store(this,e):i)}return r}rawGet(e){return this.data[e]}rawSet(e,t){if(e!==(0|e)||e<0||e>99999)throw new Error("Invalid array index "+JSON.stringify(e));for(this.data[e]=t;this.data.length>0&&void 0===this.data[this.data.length-1];)this.data.pop()}merge(e,t){if(!(e instanceof Array))return!1;for(let r=0;r<e.length;r++)this.setIndex(r,e[r],t);if(t&&this.data.length>e.length){for(let t=e.length;t<this.data.length;t++){let e=this.data[t];void 0!==e&&this.emitChange(t,void 0,e)}this.data.length=e.length}return!0}iterateIndexes(e){for(let t=0;t<this.data.length;t++)e.addChild(t)}normalizeIndex(e){return 0|e}}class c extends d{constructor(){super(...arguments),this.data=new Map}getType(){return"map"}getRecursive(t){e&&this.addObserver(h,e)&&e.cleaners.push(this);let r=new Map;return this.data.forEach((e,i)=>{r.set(i,e instanceof d?t?e.getRecursive(t-1):new Store(this,i):e)}),r}rawGet(e){return this.data.get(e)}rawSet(e,t){void 0===t?this.data.delete(e):this.data.set(e,t)}merge(e,t){return e instanceof Map&&(e.forEach((e,r)=>{this.setIndex(r,e,t)}),t&&this.data.forEach((t,r)=>{e.has(r)||this.setIndex(r,void 0,!1)}),!0)}iterateIndexes(e){this.data.forEach((t,r)=>{e.addChild(r)})}normalizeIndex(e){return e}}class u extends c{getType(){return"object"}getRecursive(t){e&&this.addObserver(h,e)&&e.cleaners.push(this);let r={};return this.data.forEach((e,i)=>{r[i]=e instanceof d?t?e.getRecursive(t-1):new Store(this,i):e}),r}merge(e,t){if(!e||e.constructor!==Object)return!1;for(let r in e)this.setIndex(r,e[r],t);return t&&this.data.forEach((t,r)=>{e.hasOwnProperty(r)||this.setIndex(r,void 0,!1)}),!0}normalizeIndex(e){return""+e}}new class extends d{getType(){return"obect"}getRecursive(e){return{}}rawGet(e){}rawSet(e){throw new Error("Updating a detached Store does not make sense")}merge(e,t){throw new Error("Updating a detached Store does not make sense")}iterateIndexes(e){}normalizeIndex(e){return e}};class f{constructor(e,t){this.sourceStore=e,this.targetData=t}onChange(e,t,r,i){this.sourceStore.set(this.targetData),e.removeObserver(t,this)}}export class Store{constructor(e,t){if(void 0===t)this.collection=new l,this.idx=0,void 0!==e&&this.collection.rawSet(0,Store._valueToData(e));else{if(!(e instanceof d))throw new Error("1st parameter should be an ObsCollection if the 2nd is also given");this.collection=e,this.idx=t}}index(){return this.idx}_read(){return this.collection.rawGet(this.idx)}_clean(e){this.collection.removeObserver(this.idx,e)}get(e,t){let r=this._observe();return r instanceof d?r.getRecursive(null==t?-1:t):void 0===r?e:r}getType(){let e=this._observe();return e instanceof d?e.getType():typeof e}getNumber(e){let t=this._observe();if("number"==typeof t)return t;if(void 0===t&&void 0!==e)return e;throw this.getTypeError("number",t)}getString(e){let t=this._observe();if("string"==typeof t)return t;if(void 0===t&&void 0!==e)return e;throw this.getTypeError("string",t)}getBoolean(e){let t=this._observe();if("boolean"==typeof t)return t;if(void 0===t&&void 0!==e)return e;throw this.getTypeError("boolean",t)}getArray(e,t){let r=this._observe();if(r instanceof l)return r.getRecursive(null==t?-1:t);if(void 0===r&&void 0!==e)return e;throw this.getTypeError("array",r)}getObject(e,t){let r=this._observe();if(r instanceof u)return r.getRecursive(null==t?-1:t);if(void 0===r&&void 0!==e)return e;throw this.getTypeError("object",r)}getMap(e,t){let r=this._observe();if(r instanceof c)return r.getRecursive(null==t?-1:t);if(void 0===r&&void 0!==e)return e;throw this.getTypeError("map",r)}getTypeError(e,t){return void 0===t?new Error(`Expecting ${e} but got undefined, and no default value was given`):new Error(`Expecting ${e} but got ${t instanceof d?t.getRecursive(-1):JSON.stringify(t)}`)}set(e){this.collection.setIndex(this.idx,e,!0)}merge(e){this.collection.setIndex(this.idx,e,!1)}delete(){this.collection.setIndex(this.idx,void 0,!0)}ref(...e){let t=this;for(let r=0;r<e.length;r++){let i=t._observe();if(!(i instanceof d)){if(void 0!==i)throw new Error(`Value ${JSON.stringify(i)} is not a collection (nor undefined) in step ${r} of $(${JSON.stringify(e)})`);let n=new u,s=n;for(;r<e.length-1;r++){let t=new u;s.data.set(""+e[r],t),s=t}let o=""+e[e.length-1];return s.addObserver(o,new f(t,n)),new Store(s,o)}t=new Store(i,i.normalizeIndex(e[r]))}return t}_observe(){return e&&this.collection.addObserver(this.idx,e)&&e.cleaners.push(this),this.collection.rawGet(this.idx)}push(e){let t=this.collection.rawGet(this.idx);if(void 0===t)t=new l,this.collection.setIndex(this.idx,t,!0);else if(!(t instanceof l))throw new Error("push() is only allowed for an array or undefined (which would become an array)");let r=Store._valueToData(e),i=t.data.length;return t.data.push(r),t.emitChange(i,r,void 0),i}onEach(t,r=Store._makeDefaultSortKey){if(!e)throw new Error("onEach() is only allowed from a render scope");let i=this._observe();if(i instanceof d){let n=new o(e.parentElement,e.lastChild||e.precedingSibling,e.queueOrder+1,i,t,r);i.addObserver(h,n),e.cleaners.push(n),e.lastChild=n,n.renderInitial()}else if(void 0!==i)throw new Error("onEach() attempted on a value that is neither a collection nor undefined")}static _valueToData(e){if("object"==typeof e&&e){if(e instanceof Store)return e._observe();if(e instanceof Map){let t=new c;return e.forEach((e,r)=>{let i=Store._valueToData(e);void 0!==i&&t.rawSet(r,i)}),t}if(e instanceof Array){let t=new l;for(let r=0;r<e.length;r++){let i=Store._valueToData(e[r]);void 0!==i&&t.rawSet(r,i)}return t}if(e.constructor===Object){let t=new u;for(let r in e){let i=Store._valueToData(e[r]);void 0!==i&&t.rawSet(r,i)}return t}return e}return e}static _makeDefaultSortKey(e){return e.index()}}export function node(t,...r){if(!e)throw new Error("node() outside of a render scope");let i;if(t.indexOf(".")>=0){let e=t.split("."),r=e.shift();i=document.createElement(r),i.className=e.join(" ")}else i=document.createElement(t);e.addNode(i);for(let t of r){let r=typeof t;if("function"===r){let r=new s(i,void 0,e.queueOrder+1,t);r.update(),e.cleaners.push(r)}else if("string"===r||"number"===r)i.textContent=t;else if("object"===r&&t&&t.constructor===Object)for(let e in t)p(i,e,t[e]);else if(null!=t)throw new Error("Unexpected argument "+JSON.stringify(t))}}export function text(t){if(!e)throw new Error("text() outside of a render scope");t&&e.addNode(document.createTextNode(t))}export function prop(t,r){if(!e)throw new Error("prop() outside of a render scope");if("object"==typeof t)for(let r in t)p(e.parentElement,r,t[r]);else p(e.parentElement,t,r)}export function clean(t){if(!e)throw new Error("clean() outside of a render scope");e.cleaners.push({_clean:t})}export function scope(t){if(!e)throw new Error("scope() outside of a render scope");let r=new s(e.parentElement,e.lastChild||e.precedingSibling,e.queueOrder+1,t);e.lastChild=r,r.update(),e.cleaners.push(r)}class g{constructor(e){this.scope=e}unmount(){this.scope.remove()}}export function mount(t,r){if(e)throw new Error("mount() from within a render scope");let i=new s(t,void 0,0,r);return i.update(),new g(i)}export function peek(t){let r=e;e=void 0;try{return t()}finally{e=r}}function p(t,r,i){"value"===r||"className"===r||"selectedIndex"===r||!0===i||!1===i?t[r]=i:"function"==typeof i?(t.addEventListener(r,i),e&&clean(()=>t.removeEventListener(r,i))):"style"===r&&"object"==typeof i?Object.assign(t.style,i):"text"===r?t.textContent=i:t.setAttribute(r,i)}function v(e){console.error(new Error("internal error "+e))}function w(e){console.error(e),setTimeout(()=>{throw e},0)}
1
+ let e,t=[],i=new Set,n=!0,r=0;function s(e){if(!i.has(e)){if(r>42)throw new Error("Too many recursive updates from observes");t.length?e.queueOrder<t[t.length-1].queueOrder&&(n=!1):setTimeout(o,0),t.push(e),i.add(e)}}function o(){for(let e=0;e<t.length;){n||(t.splice(0,e),e=0,t.sort((e,t)=>e.queueOrder-t.queueOrder),n=!0);let s=t.length;for(;e<s&&n;e++){let n=t[e];i.delete(n),n.queueRun()}r++}t.length=0,r=0}function a(e){if("string"==typeof e)return e+"";{let t=function(e,t){let i="";for(;e>0;)i+=String.fromCharCode(t?65535-e%65533:2+e%65533),e=Math.floor(e/65533);return i}(Math.abs(Math.round(e)),e<0);return String.fromCharCode(128+(e>0?t.length:-t.length))+t}}class h{constructor(e,t,i){this.cleaners=[],this.isDead=!1,this.parentElement=e,this.precedingSibling=t,this.queueOrder=i}findPrecedingNode(){let e=this.precedingSibling;for(;e;){if(e instanceof Node)return e;let t=e.findLastNode();if(t)return t;e=e.precedingSibling}}findLastNode(){return this.lastChild instanceof Node?this.lastChild:this.lastChild instanceof h?this.lastChild.findLastNode()||this.lastChild.findPrecedingNode():void 0}addNode(e){if(!this.parentElement)throw new I(!0);let t=this.findLastNode()||this.findPrecedingNode();this.parentElement.insertBefore(e,t?t.nextSibling:this.parentElement.firstChild),this.lastChild=e}remove(){if(this.parentElement){let e=this.findLastNode();if(e){let t=this.findPrecedingNode();for(;e!==t;){if(!e)return E(1);let t=e.previousSibling||void 0;this.parentElement.removeChild(e),e=t}}this.lastChild=void 0}this._clean()}_clean(){this.isDead=!0;for(let e of this.cleaners)e._clean(this);this.cleaners.length=0}onChange(e,t,i){s(this)}}class l extends h{constructor(e,t,i,n){super(e,t,i),this.renderer=n}queueRun(){e&&E(2),this.isDead||(this.remove(),this.isDead=!1,this.update())}update(){let t=e;e=this;try{this.renderer()}catch(e){C(e)}e=t}}class d{constructor(e,t,i){this.scope=e,this.collection=t,this.triggerCount=i,this.count=t.getCount(),t.addObserver(f,this),e.cleaners.push(this)}onChange(e,t,i){void 0===t?!this.triggerCount&&--this.count||s(this.scope):void 0===i&&(!this.triggerCount&&this.count++||s(this.scope))}_clean(){this.collection.removeObserver(f,this)}}class c extends h{constructor(e,t,i,n,r,s){super(e,t,i),this.byPosition=[],this.byIndex=new Map,this.newIndexes=new Set,this.removedIndexes=new Set,this.collection=n,this.renderer=r,this.makeSortKey=s}onChange(e,t,i){void 0===i?this.removedIndexes.has(e)?this.removedIndexes.delete(e):(this.newIndexes.add(e),s(this)):void 0===t&&(this.newIndexes.has(e)?this.newIndexes.delete(e):(this.removedIndexes.add(e),s(this)))}queueRun(){if(this.isDead)return;let e=this.removedIndexes;this.removedIndexes=new Set,e.forEach(e=>{this.removeChild(e)}),e=this.newIndexes,this.newIndexes=new Set,e.forEach(e=>{this.addChild(e)})}_clean(){super._clean(),this.collection.observers.delete(this);for(const[e,t]of this.byIndex)t._clean();this.byPosition.length=0,this.byIndex.clear()}renderInitial(){if(!e)return E(3);let t=e;this.collection.iterateIndexes(this),e=t}addChild(e){let t=new u(this.parentElement,void 0,this.queueOrder+1,this,e);this.byIndex.set(e,t),t.update()}removeChild(e){let t=this.byIndex.get(e);if(!t)return E(6);this.byIndex.delete(e),this.removeFromPosition(t),t.remove()}findPosition(e){let t=this.byPosition,i=0,n=t.length;if(!n||e>t[n-1].sortStr)return n;for(;i<n;){let r=i+n>>1;t[r].sortStr<e?i=r+1:n=r}return i}insertAtPosition(e){let t=this.findPosition(e.sortStr);this.byPosition.splice(t,0,e),e.precedingSibling=t>0?this.byPosition[t-1]:this.precedingSibling,t+1<this.byPosition.length?this.byPosition[t+1].precedingSibling=e:this.lastChild=e}removeFromPosition(e){if(""===e.sortStr)return;let t=this.findPosition(e.sortStr);for(;;){if(this.byPosition[t]===e)return this.byPosition.splice(t,1),void(t<this.byPosition.length?this.byPosition[t].precedingSibling=t>0?this.byPosition[t-1]:this.precedingSibling:this.lastChild=this.byPosition.length?this.byPosition[this.byPosition.length-1]:void 0);if(++t>=this.byPosition.length||this.byPosition[t].sortStr!==e.sortStr)return E(5)}}}class u extends h{constructor(e,t,i,n,r){super(e,t,i),this.sortStr="",this.parent=n,this.itemIndex=r}queueRun(){e&&E(4),this.isDead||(this.remove(),this.isDead=!1,this.update())}update(){let t=e;e=this;let i,n=new Store(this.parent.collection,this.itemIndex);try{i=this.parent.makeSortKey(n)}catch(e){C(e)}let r=this.sortStr,s=null==i?"":(o=i)instanceof Array?o.map(a).join(""):a(o);var o;if(""!==r&&r!==s&&this.parent.removeFromPosition(this),this.sortStr=s,""!==s){s!==r&&this.parent.insertAtPosition(this);try{this.parent.renderer(n)}catch(e){C(e)}}e=t}}const f={};class p{constructor(){this.observers=new Map}addObserver(e,t){t=t;let i=this.observers.get(e);if(i){if(i.has(t))return!1;i.add(t)}else this.observers.set(e,new Set([t]));return!0}removeObserver(e,t){this.observers.get(e).delete(t)}emitChange(e,t,i){let n=this.observers.get(e);n&&n.forEach(n=>n.onChange(e,t,i)),n=this.observers.get(f),n&&n.forEach(n=>n.onChange(e,t,i))}_clean(e){this.removeObserver(f,e)}setIndex(e,t,i){const n=this.rawGet(e);if(!(n instanceof p)||t instanceof Store||!n.merge(t,i)){let i=x(t);i!==n&&(this.rawSet(e,i),this.emitChange(e,i,n))}}}class g extends p{constructor(){super(...arguments),this.data=[]}getType(){return"array"}getRecursive(t){e&&this.addObserver(f,e)&&e.cleaners.push(this);let i=[];for(let e=0;e<this.data.length;e++){let n=this.data[e];i.push(n instanceof p?t?n.getRecursive(t-1):new Store(this,e):n)}return i}rawGet(e){return this.data[e]}rawSet(e,t){if(e!==(0|e)||e<0||e>999999)throw new Error("Invalid array index "+JSON.stringify(e));for(this.data[e]=t;this.data.length>0&&void 0===this.data[this.data.length-1];)this.data.pop()}merge(e,t){if(!(e instanceof Array))return!1;for(let i=0;i<e.length;i++)this.setIndex(i,e[i],t);if(t&&this.data.length>e.length){for(let t=e.length;t<this.data.length;t++){let e=this.data[t];void 0!==e&&this.emitChange(t,void 0,e)}this.data.length=e.length}return!0}iterateIndexes(e){for(let t=0;t<this.data.length;t++)void 0!==this.data[t]&&e.addChild(t)}normalizeIndex(e){if("number"==typeof e)return e;if("string"==typeof e){let t=0|e;if(e.length&&t==e)return e}throw new Error("Invalid array index "+JSON.stringify(e))}getCount(){return this.data.length}}class v extends p{constructor(){super(...arguments),this.data=new Map}getType(){return"map"}getRecursive(t){e&&this.addObserver(f,e)&&e.cleaners.push(this);let i=new Map;return this.data.forEach((e,n)=>{i.set(n,e instanceof p?t?e.getRecursive(t-1):new Store(this,n):e)}),i}rawGet(e){return this.data.get(e)}rawSet(e,t){void 0===t?this.data.delete(e):this.data.set(e,t)}merge(e,t){return e instanceof Map&&(e.forEach((e,i)=>{this.setIndex(i,e,t)}),t&&this.data.forEach((t,i)=>{e.has(i)||this.setIndex(i,void 0,!1)}),!0)}iterateIndexes(e){this.data.forEach((t,i)=>{e.addChild(i)})}normalizeIndex(e){return e}getCount(){return this.data.size}}class y extends v{getType(){return"object"}getRecursive(t){e&&this.addObserver(f,e)&&e.cleaners.push(this);let i={};return this.data.forEach((e,n)=>{i[n]=e instanceof p?t?e.getRecursive(t-1):new Store(this,n):e}),i}merge(e,t){if(!e||e.constructor!==Object)return!1;for(let i in e)this.setIndex(i,e[i],t);return t&&this.data.forEach((t,i)=>{e.hasOwnProperty(i)||this.setIndex(i,void 0,!1)}),!0}normalizeIndex(e){let t=typeof e;if("string"===t)return e;if("number"===t)return""+e;throw new Error("Invalid object index "+JSON.stringify(e))}getCount(){let e=0;for(let t of this.data)e++;return e}}export class Store{constructor(e,t){if(void 0===t)this.collection=new g,this.idx=0,void 0!==e&&this.collection.rawSet(0,x(e));else{if(!(e instanceof p))throw new Error("1st parameter should be an ObsCollection if the 2nd is also given");this.collection=e,this.idx=t}}index(){return this.idx}_clean(e){this.collection.removeObserver(this.idx,e)}get(...e){return this.query({path:e})}peek(...e){return this.query({path:e,peek:!0})}getNumber(...e){return this.query({path:e,type:"number"})}getString(...e){return this.query({path:e,type:"string"})}getBoolean(...e){return this.query({path:e,type:"boolean"})}getFunction(...e){return this.query({path:e,type:"function"})}getArray(...e){return this.query({path:e,type:"array"})}getObject(...e){return this.query({path:e,type:"object"})}getMap(...e){return this.query({path:e,type:"map"})}getOr(e,...t){let i=typeof e;return"object"===i&&(e instanceof Map?i="map":e instanceof Array&&(i="array")),this.query({type:i,defaultValue:e,path:t})}query(t){if(t.peek&&e){let i=e;e=void 0;let n=this.query(t);return e=i,n}let i=(t.path&&t.path.length?this.ref(...t.path):this)._observe();if(t.type&&(void 0!==i||void 0===t.defaultValue)){let e=i instanceof p?i.getType():null===i?"null":typeof i;if(e!==t.type)throw new TypeError(`Expecting ${t.type} but got ${e}`)}return i instanceof p?i.getRecursive(null==t.depth?-1:t.depth-1):void 0===i?t.defaultValue:i}isEmpty(...t){let i=this.ref(...t)._observe();if(i instanceof p){if(e){return!new d(e,i,!1).count}return!i.getCount()}if(void 0===i)return!0;throw new Error("isEmpty() expects a collection or undefined, but got "+JSON.stringify(i))}count(...t){let i=this.ref(...t)._observe();if(i instanceof p){if(e){return new d(e,i,!0).count}return i.getCount()}if(void 0===i)return 0;throw new Error("count() expects a collection or undefined, but got "+JSON.stringify(i))}getType(...e){let t=this.ref(...e)._observe();return t instanceof p?t.getType():null===t?"null":typeof t}set(...e){let t=e.pop(),i=this.makeRef(...e);i.collection.setIndex(i.idx,t,!0)}merge(e){this.collection.setIndex(this.idx,e,!1)}delete(...e){let t=this.makeRef(...e);t.collection.setIndex(t.idx,void 0,!0)}push(e){let t=this.collection.rawGet(this.idx);if(void 0===t)t=new g,this.collection.setIndex(this.idx,t,!0);else if(!(t instanceof g))throw new Error("push() is only allowed for an array or undefined (which would become an array)");let i=x(e),n=t.data.length;return t.data.push(i),t.emitChange(n,i,void 0),n}modify(e){this.set(e(this.query({peek:!0})))}ref(...e){let t=this;for(let i=0;i<e.length;i++){let n=t._observe();if(!(n instanceof p)){if(void 0!==n)throw new Error(`Value ${JSON.stringify(n)} is not a collection (nor undefined) in step ${i} of $(${JSON.stringify(e)})`);return new w}t=new Store(n,n.normalizeIndex(e[i]))}return t}makeRef(...e){let t=this;for(let i=0;i<e.length;i++){let n=t.collection.rawGet(t.idx);if(!(n instanceof p)){if(void 0!==n)throw new Error(`Value ${JSON.stringify(n)} is not a collection (nor undefined) in step ${i} of $(${JSON.stringify(e)})`);n=new y,t.collection.rawSet(t.idx,n),t.collection.emitChange(t.idx,n,void 0)}t=new Store(n,n.normalizeIndex(e[i]))}return t}_observe(){return e&&this.collection.addObserver(this.idx,e)&&e.cleaners.push(this),this.collection.rawGet(this.idx)}onEach(...t){let i=S,n=t.pop();if("function"!=typeof t[t.length-1]||"function"!=typeof n&&null!=n||(null!=n&&(i=n),n=t.pop()),"function"!=typeof n)throw new Error("onEach() expects a render function as its last argument but got "+JSON.stringify(n));if(!e)throw new I(!1);let r=this.ref(...t)._observe();if(r instanceof p){let t=new c(e.parentElement,e.lastChild||e.precedingSibling,e.queueOrder+1,r,n,i);r.addObserver(f,t),e.cleaners.push(t),e.lastChild=t,t.renderInitial()}else if(void 0!==r)throw new Error("onEach() attempted on a value that is neither a collection nor undefined")}map(e){let t=new Store(new Map);return this.onEach(i=>{let n=e(i);if(void 0!==n){let e=i.index();t.set(e,n),clean(()=>{t.delete(e)})}}),t}multiMap(e){let t=new Store(new Map);return this.onEach(i=>{let n,r=e(i);if(r.constructor===Object){for(let e in r)t.set(e,r[e]);n=Object.keys(r)}else{if(!(r instanceof Map))return;r.forEach((e,i)=>{t.set(i,e)}),n=Array.from(r.keys())}n.length&&clean(()=>{for(let e of n)t.delete(e)})}),t}isDetached(){return!1}}class w extends Store{isDetached(){return!0}}export function node(t="",...i){if(!e)throw new I(!0);let n;if(t instanceof Element)n=t;else{let e,i=t.indexOf(".");i>=0&&(e=t.substr(i+1),t=t.substr(0,i)),n=document.createElement(t||"div"),e&&(n.className=e.replaceAll("."," "))}e.addNode(n);for(let t of i){let i=typeof t;if("function"===i){let i=new l(n,void 0,e.queueOrder+1,t);i.update(),e.cleaners.push(i)}else if("string"===i||"number"===i)n.textContent=t;else if("object"===i&&t&&t.constructor===Object)for(let e in t)b(n,e,t[e]);else if(t instanceof Store)m(n,t);else if(null!=t)throw new Error("Unexpected argument "+JSON.stringify(t))}}function m(e,t){let i,n=e.getAttribute("type"),r=t.query({peek:!0});"checkbox"===n?(void 0===r?t.set(e.checked):e.checked=r,i=()=>t.set(e.checked)):"radio"===n?(void 0===r?e.checked&&t.set(e.value):e.checked=r===e.value,i=()=>{e.checked&&t.set(e.value)}):(void 0===r?t.set(e.value):e.value=r,i=()=>t.set(e.value)),e.addEventListener("input",i),clean(()=>{e.removeEventListener("input",i)})}export function text(t){if(!e)throw new I(!0);null!=t&&e.addNode(document.createTextNode(t))}export function prop(t,i){if(!e||!e.parentElement)throw new I(!0);if("object"==typeof t)for(let i in t)b(e.parentElement,i,t[i]);else b(e.parentElement,t,i)}export function getParentElement(){if(!e||!e.parentElement)throw new I(!0);return e.parentElement}export function clean(t){if(!e)throw new I(!1);e.cleaners.push({_clean:t})}export function observe(e){mount(void 0,e)}export function mount(t,i){let n;t||!e?n=new l(t,void 0,0,i):(n=new l(e.parentElement,e.lastChild||e.precedingSibling,e.queueOrder+1,i),e.lastChild=n),n.update(),e&&e.cleaners.push(n)}export function peek(t){let i=e;e=void 0;try{return t()}finally{e=i}}function b(e,t,i){if("class"!==t&&"className"!==t||"object"!=typeof i)"value"===t||"className"===t||"selectedIndex"===t||!0===i||!1===i?e[t]=i:"function"==typeof i?(e.addEventListener(t,i),clean(()=>e.removeEventListener(t,i))):"style"===t&&"object"==typeof i?Object.assign(e.style,i):"text"===t?e.textContent=i:e.setAttribute(t,i);else for(let t in i)i[t]?e.classList.add(t):e.classList.remove(t)}function x(e){if("object"==typeof e&&e){if(e instanceof Store)return e._observe();if(e instanceof Map){let t=new v;return e.forEach((e,i)=>{let n=x(e);void 0!==n&&t.rawSet(i,n)}),t}if(e instanceof Array){let t=new g;for(let i=0;i<e.length;i++){let n=x(e[i]);void 0!==n&&t.rawSet(i,n)}return t}if(e.constructor===Object){let t=new y;for(let i in e){let n=x(e[i]);void 0!==n&&t.rawSet(i,n)}return t}return e}return e}function S(e){return e.index()}function E(e){let t=new Error("internal error "+e);setTimeout(()=>{throw t},0)}function C(e){setTimeout(()=>{throw e},0)}class I extends Error{constructor(e){super(`Operation not permitted outside of ${e?"a mount":"an observe"}() scope`)}}Array.from;String.prototype.replaceAll||(String.prototype.replaceAll=function(e,t){return this.split(e).join(t)});
package/package.json CHANGED
@@ -1,31 +1,43 @@
1
1
  {
2
2
  "name": "aberdeen",
3
- "version": "0.0.8",
4
- "description": "",
5
- "main": "index.js",
3
+ "version": "0.0.11",
4
+ "description": "A TypeScript/JavaScript library for quickly building performant declarative user interfaces without the use of a virtual DOM.",
5
+ "main": "dist/aberdeen.js",
6
+ "types": "dist/aberdeen.d.js",
6
7
  "scripts": {
7
- "build": "tsc && terser --module --compress --mangle -- dist/aberdeen.js > dist/aberdeen.min.js",
8
- "coverage": "([ src/aberdeen.ts -nt tests/build/aberdeen.js ] && tsc -t ES2015 -m commonjs --outdir tests/build src/aberdeen.ts) ; nyc mocha --file tests/_init.js tests/[^_]*.js",
9
- "test": "([ src/aberdeen.ts -nt tests/build/aberdeen.js ] && tsc -t ES2015 -m commonjs --outdir tests/build src/aberdeen.ts) ; mocha --file tests/_init.js tests/[^_]*.js",
10
- "prepack": "npm run build"
8
+ "build": "$npm_execpath run build-dist && $npm_execpath run build-docs",
9
+ "build-dist": "tsc && terser --module --compress --mangle -- dist/aberdeen.js > dist/aberdeen.min.js",
10
+ "build-docs": "typedoc --excludePrivate --excludeInternal src/aberdeen.ts",
11
+ "build-test": "[ tests/build/aberdeen.js -nt src/aberdeen.ts ] || tsc -t ES2015 -m commonjs --outdir tests/build src/aberdeen.ts",
12
+ "coverage": "$npm_execpath run build-test && nyc mocha --file tests/_init.js tests/[^_]*.js",
13
+ "test": "$npm_execpath run build-test && mocha --file tests/_init.js tests/[^_]*.js",
14
+ "prepack": "$npm_execpath run test && $npm_execpath run build"
11
15
  },
12
- "author": "",
16
+ "author": "Frank van Viegen",
13
17
  "license": "ISC",
14
- "dependencies": {
15
- },
16
18
  "devDependencies": {
19
+ "mocha": "^9.1.3",
17
20
  "nyc": "^15.0.1",
18
21
  "terser": "^4.6.13",
19
- "fast-deep-equal": "^3.1.1",
20
- "mocha": "^7.1.2",
21
- "typescript": "^3.8.3"
22
+ "typedoc": "^0.22.10",
23
+ "typescript": "^4.5.4",
24
+ "fast-equals": "^2.0.4"
22
25
  },
23
26
  "nyc": {
24
- "reporter": ["text-summary", "lcov"],
27
+ "reporter": [
28
+ "text-summary",
29
+ "lcov"
30
+ ],
25
31
  "temp-directory": "./coverage/.nyc_output",
26
32
  "sourceMap": true,
27
- "include": ["tests/build/**"],
33
+ "include": [
34
+ "tests/build/**"
35
+ ],
28
36
  "exclude": []
29
37
  },
30
- "files": ["dist"]
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "dependencies": {
42
+ }
31
43
  }