Skip to content

Commit 1b2a46f

Browse files
committed
2.0.9 - fix
1 parent 7a5f7b8 commit 1b2a46f

10 files changed

Lines changed: 73 additions & 18 deletions

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ npm i active-data --save
1818

1919
#### Or simply download \*.js file
2020

21-
[active-data.js@2.0.8](https://github.com/forceuser/active-data/releases/download/2.0.8/active-data.js)
21+
[active-data.js@2.0.9](https://github.com/forceuser/active-data/releases/download/2.0.9/active-data.js)
2222

23-
[active-data.modern.js@2.0.8](https://github.com/forceuser/active-data/releases/download/2.0.8/active-data.modern.js) *for modern browsers only (see [.browserlistrc](https://github.com/forceuser/active-data/blob/master/.browserslistrc))*
23+
[active-data.modern.js@2.0.9](https://github.com/forceuser/active-data/releases/download/2.0.9/active-data.modern.js) *for modern browsers only (see [.browserlistrc](https://github.com/forceuser/active-data/blob/master/.browserslistrc))*
2424

25-
[active-data.esm.mjs@2.0.8](https://github.com/forceuser/active-data/releases/download/2.0.8/active-data.esm.mjs) *import as esm module*
25+
[active-data.esm.mjs@2.0.9](https://github.com/forceuser/active-data/releases/download/2.0.9/active-data.esm.mjs) *import as esm module*
2626

2727
#### Or just load from CDN
2828

2929
```html
30-
<script src="//cdn.jsdelivr.net/npm/active-data@2.0.8/dist/active-data.js" integrity="sha512-+AMSIfx43N6XcUrFXYyR+N4OiTbcbY5yhKesJqneFuH8LCznc36BuwolCkT6b/SZr/BJgW1/hyVtrpswsutiNQ==" crossorigin="anonymous">
30+
<script src="//cdn.jsdelivr.net/npm/active-data@2.0.9/dist/active-data.js" integrity="sha512-RJ/dpHGWQAb6xzM18sKhvSCRevr2n/JvcVr//I5+WkMdRiWPpZq7OyqcocszAJkTADodrNtVTaGqZXsui5errQ==" crossorigin="anonymous">
3131
</script>
3232
```
3333

3434
*if you need only modern browsers then use script below:*
3535

3636
```html
37-
<script src="//cdn.jsdelivr.net/npm/active-data@2.0.8/dist/active-data.modern.js" integrity="sha512-we+scNmK8I2rWuKEBBEKWUDIHGtaxrHYV/6BgKzGnAdgoPeznFOqx/kRxb0nWkRfIKTJfh2VPrrDMBjNZNsYTw==" crossorigin="anonymous">
37+
<script src="//cdn.jsdelivr.net/npm/active-data@2.0.9/dist/active-data.modern.js" integrity="sha512-uqDQ12AxHikxyR5Ly7SLYankqs46S4vL6VKeg2Q/yrMS+GNOh75TXQkvzNpDr+Is5BGhsCcmTb5VDvUkPeVLWg==" crossorigin="anonymous">
3838
</script>
3939
```
4040

@@ -52,7 +52,7 @@ And then use **activeData** as global variable
5252

5353
```html
5454
<script type="module">
55-
import {default as activeData, observable, reaction} from "//cdn.jsdelivr.net/npm/active-data@2.0.8/dist/active-data.esm.mjs";
55+
import {default as activeData, observable, reaction} from "//cdn.jsdelivr.net/npm/active-data@2.0.9/dist/active-data.esm.mjs";
5656
5757
window.data = observable({c: 1});
5858
reaction(() => {

dist/active-data.esm.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const privateMap=new WeakMap,initPrivate=e=>privateMap.set(e,{}),$=e=>privateMap.get(e);export class Manager{constructor(e){const t=this;initPrivate(t);const n=$(t);n.t=0,n.i=0,n.o=Symbol("dataSource"),n.s=new WeakMap,n.options={enabled:!0,l:!1,u:10,p:"$$watch",h:"$$watchDeep",m:null,g:50,getTime:"undefined"!=typeof performance?()=>performance.now():()=>Date.now()},n.M=[],n.v=new Set,t.$(e),t.O=t.O.bind(t),t.j=t.j.bind(t),t.R=t.R.bind(t),t.k=t.k.bind(t),t.P=t.P.bind(t),t.S=t.S.bind(t),t.D=t.D.bind(t),t.U=t.O,t.A=t.j,t.I=t.R,t.W=t.k,"undefined"!=typeof process&&"test"===process.env.NODE_ENV&&(t.K=n)}P(e,t,n){[].concat(n||Object.keys(e)).forEach(n=>{Object.defineProperty(t,n,{T:!0,get(){return Reflect.get(e,n,this)},set(t){return Reflect.set(e,n,t,this)}})})}$(e={}){$(this).options=Object.assign($(this).options,e)}C(){return Object.assign({},$(this).options)}O(e){const t=this,n=$(t);if(!e)return e;if(e.constructor!==Object&&e.constructor!==Array&&"function"!=typeof e)return e;if(t.S(e))return e;const r=Array.isArray(e);let i=n.s.get(e);if(!i){const o=new Map,a={};Object.keys(e).forEach(n=>{const r=Object.getOwnPropertyDescriptor(e,n);r&&"function"==typeof r.get&&(a[n]=t.k(r.get))});const s=e=>{e.L=!0,e.q&&e.q(),e.valid&&(e.valid=!1,e.B.forEach(e=>s(e))),e.B.clear()},c=e=>{const t=new Set;return o.set(e,t),t};let f=!1;const l=(r,s)=>{const l=s===n.options.h?n.options.p:s;if(s===n.options.h){if(f)return;f=!0,Object.keys(e).forEach(r=>{if("object"==typeof e[r]){t.O(e[r])[n.options.h]}}),f=!1}l===n.options.p&&Object.keys(a).forEach(e=>{a[e].call(i)});const u=o.get(l)||c(l);u.has(r)||(u.add(r),r.F.set(e,e=>{u.delete(e),0===u.size&&o.delete(l)}))},u={G:o,H:e,J:l},p=e=>{const r=e=>s(e);if(null==e)[...u.G.values()].forEach(e=>e.forEach(r));else{const t=u.G.get(e);t&&t.forEach(r);const i=u.G.get(n.options.p);i&&i.forEach(r)}n.N||1!==n.i||(n.options.l?t.V():t.X())};i=new Proxy(e,{get:(i,o,a)=>{if(o===n.o)return e;let s;if(n.M.length&&(s=n.M[n.M.length-1],l(s,o)),o===n.options.p||o===n.options.h)return a;const c=Reflect.get(i,o,a);return r&&"function"==typeof c&&"constructor"!==o?new Proxy(c,{apply:(t,r,i)=>{const a=n.M.length?n.M[n.M.length-1]:null;if(a&&l(a,n.options.p),["copyWithin","fill","pop","push","reverse","shift","sort","splice","unshift"].includes(o)){n.i++;try{p()}finally{n.i--}}return t.apply(e,i)}}):"object"==typeof c?t.O(c):c},set:(e,t,r,i)=>{if(r!==Reflect.get(e,t,i)||Array.isArray(e)&&"length"===t){n.i++;try{Reflect.set(e,t,r,i),p(t)}finally{n.i--}}return!0},defineProperty:(e,n,r)=>(r&&"function"==typeof r.get&&(a[n]=t.k(r.get)),Reflect.defineProperty(e,n,r)),deleteProperty:(e,t)=>{n.i++;try{t in a&&delete a[t],p(t)}finally{n.i--}return Reflect.deleteProperty(e,t)}}),n.s.set(e,i)}return i}k(e,t={}){if(e.Y)return e;const n=t.q,r=t.Z,i=$(this),o={id:++i.t,active:!0,valid:!1,q:n,Z:r,value:void 0,B:new Set,F:new Map,_:()=>{[...o.F.values()].forEach(e=>e(o)),o.F.clear()}},a=function(){if(!o.active)return e.call(this,this);if(o.ee)console.warn('Detected cross reference inside computed properties! "undefined" will be returned to prevent infinite loop');else{if(i.M.length&&o.B.add(i.M[i.M.length-1]),o.valid)return o.value;o.ee=!0,o._(),i.M.push(o);try{const t=this?i.s.get(this)||this:null;o.L=!1;const n=e.call(t,t);return o.valid=!o.L,o.value=n,n}finally{o.ee=!1,i.M.pop()}}};return a._=()=>{o._(),o.active=!1,r&&r()},a.Y=e,a}R(e,t,n,r){Object.defineProperty(e,t,{T:!0,te:!0,get:this.k(n),set:r})}j(e,t=!0){const n=this,r=$(n),i=n.k(e,{q:()=>r.v.add(i),Z:()=>r.v.delete(i)});return r.v.add(i),t&&(r.options.l?n.V():n.X()),i}D(e){return e[$(this).o]}S(e){return null!=e[$(this).o]}V(e){const t=this,n=$(t);if(n.options.enabled){n.N=!0;try{"function"==typeof e&&e(),n.ne=!1;let r=0;for(;n.v.size;){if(r>n.options.u)throw n.v.clear(),new Error("Max iterations exceeded!");r++;const e=n.options.getTime(),i=[...n.v.values()];for(const t of i)if(n.v.delete(t),t(),n.options.getTime()-e>=n.options.g)break;n.v.size&&t.X()}"function"==typeof n.options.m&&n.options.m()}finally{n.N=!1}}}X(e,t=0){const n=$(this);if(n.options.enabled){n.N=!0;try{n.ne||(n.ne=setTimeout(()=>this.V(),t)),"function"==typeof e&&e()}finally{n.N=!1}}}}Manager.default=new Manager,Manager.default.re=Manager;export default Manager.default;export const observable=Manager.default.U;export const reaction=Manager.default.A;export const computed=Manager.default.I;export const updatable=Manager.default.W;
1+
const privateMap=new WeakMap,initPrivate=e=>privateMap.set(e,{}),$=e=>privateMap.get(e);export class Manager{constructor(e){const t=this;initPrivate(t);const n=$(t);n.t=0,n.i=0,n.o=Symbol("dataSource"),n.s=new WeakMap,n.options={enabled:!0,u:!1,l:10,p:"$$watch",h:"$$watchDeep",m:null,g:50,getTime:"undefined"!=typeof performance?()=>performance.now():()=>Date.now()},n.M=[],n.v=new Set,t.$(e),t.O=t.O.bind(t),t.j=t.j.bind(t),t.R=t.R.bind(t),t.k=t.k.bind(t),t.P=t.P.bind(t),t.S=t.S.bind(t),t.D=t.D.bind(t),t.U=t.O,t.A=t.j,t.I=t.R,t.W=t.k,"undefined"!=typeof process&&"test"===process.env.NODE_ENV&&(t.K=n)}P(e,t,n){[].concat(n||Object.keys(e)).forEach(n=>{Object.defineProperty(t,n,{T:!0,get(){return Reflect.get(e,n,this)},set(t){return Reflect.set(e,n,t,this)}})})}$(e={}){$(this).options=Object.assign($(this).options,e)}C(){return Object.assign({},$(this).options)}O(e){const t=this,n=$(t);if(!e)return e;if(e.constructor!==Object&&e.constructor!==Array&&"function"!=typeof e)return e;if(t.S(e))return e;const r=Array.isArray(e);let i=n.s.get(e);if(!i){const o=new Map,a={};Object.keys(e).forEach(n=>{const r=Object.getOwnPropertyDescriptor(e,n);r&&"function"==typeof r.get&&(a[n]=t.k(r.get))});const s=e=>{e.L=!0,e.q&&e.q(),e.valid&&(e.valid=!1,e.B.forEach(e=>s(e))),e.B.clear()},c=e=>{const t=new Set;return o.set(e,t),t};let f=!1;const u=(r,s)=>{const u=s===n.options.h?n.options.p:s;if(s===n.options.h){if(f)return;f=!0,Object.keys(e).forEach(r=>{if("object"==typeof e[r]){t.O(e[r])[n.options.h]}}),f=!1}u===n.options.p&&Object.keys(a).forEach(e=>{a[e].call(i)});const l=o.get(u)||c(u);l.has(r)||(l.add(r),r.F.set(e,e=>{l.delete(e),0===l.size&&o.delete(u)}))},l={G:o,H:e,J:u},p=e=>{const r=e=>s(e);if(null==e)[...l.G.values()].forEach(e=>e.forEach(r));else{const t=l.G.get(e);t&&t.forEach(r);const i=l.G.get(n.options.p);i&&i.forEach(r)}n.N||1!==n.i||(n.options.u?t.V():t.X())};i=new Proxy(e,{get:(i,o,a)=>{if(o===n.o)return e;let s;if(n.M.length&&(s=n.M[n.M.length-1],u(s,o)),o===n.options.p||o===n.options.h)return a;const c=Reflect.get(i,o,a);return r&&"function"==typeof c&&"constructor"!==o?new Proxy(c,{apply:(t,r,i)=>{if(["copyWithin","fill","pop","push","reverse","shift","sort","splice","unshift"].includes(o)){n.i++;try{p()}finally{n.i--}return t.apply(e,i)}return t.apply(r,i)}}):"object"==typeof c?t.O(c):c},set:(e,t,r,i)=>{if(r!==Reflect.get(e,t,i)||Array.isArray(e)&&"length"===t){n.i++;try{Reflect.set(e,t,r,i),p(t)}finally{n.i--}}return!0},defineProperty:(e,n,r)=>(r&&"function"==typeof r.get&&(a[n]=t.k(r.get)),Reflect.defineProperty(e,n,r)),deleteProperty:(e,t)=>{n.i++;try{t in a&&delete a[t],p(t)}finally{n.i--}return Reflect.deleteProperty(e,t)}}),n.s.set(e,i)}return i}k(e,t={}){if(e.Y)return e;const n=t.q,r=t.Z,i=$(this),o={id:++i.t,active:!0,valid:!1,q:n,Z:r,value:void 0,B:new Set,F:new Map,_:()=>{[...o.F.values()].forEach(e=>e(o)),o.F.clear()}},a=function(){if(!o.active)return e.call(this,this);if(o.ee)console.warn('Detected cross reference inside computed properties! "undefined" will be returned to prevent infinite loop');else{if(i.M.length&&o.B.add(i.M[i.M.length-1]),o.valid)return o.value;o.ee=!0,o._(),i.M.push(o);try{const t=this?i.s.get(this)||this:null;o.L=!1;const n=e.call(t,t);return o.valid=!o.L,o.value=n,n}finally{o.ee=!1,i.M.pop()}}};return a._=()=>{o._(),o.active=!1,r&&r()},a.Y=e,a}R(e,t,n,r){Object.defineProperty(e,t,{T:!0,te:!0,get:this.k(n),set:r})}j(e,t=!0){const n=this,r=$(n),i=n.k(e,{q:()=>r.v.add(i),Z:()=>r.v.delete(i)});return r.v.add(i),t&&(r.options.u?n.V():n.X()),i}D(e){return e[$(this).o]}S(e){return null!=e[$(this).o]}V(e){const t=this,n=$(t);if(n.options.enabled){n.N=!0;try{"function"==typeof e&&e(),n.ne=!1;let r=0;for(;n.v.size;){if(r>n.options.l)throw n.v.clear(),new Error("Max iterations exceeded!");r++;const e=n.options.getTime(),i=[...n.v.values()];for(const t of i)if(n.v.delete(t),t(),n.options.getTime()-e>=n.options.g)break;n.v.size&&t.X()}"function"==typeof n.options.m&&n.options.m()}finally{n.N=!1}}}X(e,t=0){const n=$(this);if(n.options.enabled){n.N=!0;try{n.ne||(n.ne=setTimeout(()=>this.V(),t)),"function"==typeof e&&e()}finally{n.N=!1}}}}Manager.default=new Manager,Manager.default.re=Manager;export default Manager.default;export const observable=Manager.default.U;export const reaction=Manager.default.A;export const computed=Manager.default.I;export const updatable=Manager.default.W;

dist/active-data.esm.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/active-data.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/active-data.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/active-data.modern.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/active-data.modern.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "active-data",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"description": "Reactive data manager, inspired by MobX. Automatically detects associated data and perform updates to your views or everything dependent on that data when it changes. Implemented with js Proxy objects",
55
"main": "dist/active-data.js",
66
"module": "dist/active-data.esm.mjs",

src/active-data.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ export class Manager {
226226
if (isArray && typeof value === "function" && propertyKey !== "constructor") {
227227
return new Proxy(value, {
228228
apply: (target, thisArg, argumentsList) => {
229-
const updatableState = $$.callStack.length ? $$.callStack[$$.callStack.length - 1] : null;
230-
if (updatableState) {
231-
registerRead(updatableState, $$.options.watchKey);
232-
}
233229
if (["copyWithin", "fill", "pop", "push", "reverse", "shift", "sort", "splice", "unshift"].includes(propertyKey)) {
234230
$$.intentToRun++;
235231
try {
@@ -238,8 +234,9 @@ export class Manager {
238234
finally {
239235
$$.intentToRun--;
240236
}
237+
return target.apply(dataSource, argumentsList);
241238
}
242-
return target.apply(dataSource, argumentsList);
239+
return target.apply(thisArg, argumentsList);
243240
},
244241
});
245242
}

src/i.mjs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const xlinkNS = "http://www.w3.org/1999/xlink";
2+
const xmlNS = "http://www.w3.org/XML/1998/namespace";
3+
const colonChar = 58;
4+
const xChar = 120;
5+
6+
function updateAttrs (oldVnode, vnode) {
7+
let key;
8+
const elm = vnode.elm;
9+
const oldDescriptor = Object.getOwnPropertyDescriptor(oldVnode.data, "model");
10+
const newDescriptor = Object.getOwnPropertyDescriptor(vnode.data, "model");
11+
12+
13+
if (!oldAttrs && !attrs) {return;}
14+
if (oldAttrs === attrs) {return;}
15+
oldAttrs = oldAttrs || {};
16+
attrs = attrs || {};
17+
18+
// update modified attributes, add new attributes
19+
for (key in attrs) {
20+
const cur = attrs[key];
21+
const old = oldAttrs[key];
22+
if (old !== cur) {
23+
if (cur === true) {
24+
elm.setAttribute(key, "");
25+
}
26+
else if (cur === false) {
27+
elm.removeAttribute(key);
28+
}
29+
else {
30+
if (key.charCodeAt(0) !== xChar) {
31+
elm.setAttribute(key, cur);
32+
}
33+
else if (key.charCodeAt(3) === colonChar) {
34+
// Assume xml namespace
35+
elm.setAttributeNS(xmlNS, key, cur);
36+
}
37+
else if (key.charCodeAt(5) === colonChar) {
38+
// Assume xlink namespace
39+
elm.setAttributeNS(xlinkNS, key, cur);
40+
}
41+
else {
42+
elm.setAttribute(key, cur);
43+
}
44+
}
45+
}
46+
}
47+
// remove removed attributes
48+
// use `in` operator since the previous `for` iteration uses it (.i.e. add even attributes with undefined value)
49+
// the other option is to remove all attributes with value == undefined
50+
for (key in oldAttrs) {
51+
if (!(key in attrs)) {
52+
elm.removeAttribute(key);
53+
}
54+
}
55+
}
56+
57+
export const attributesModule = {create: updateAttrs, update: updateAttrs};
58+
export default attributesModule;

0 commit comments

Comments
 (0)