@madronejs/core 1.0.16
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.
- package/LICENSE +21 -0
- package/README.md +92 -0
- package/dist/core.mjs +617 -0
- package/dist/core.umd.js +1 -0
- package/package.json +74 -0
- package/types/__spec__/decorateComputed.spec.d.ts +2 -0
- package/types/__spec__/decorateReactive.spec.d.ts +2 -0
- package/types/__spec__/examples.spec.d.ts +2 -0
- package/types/__spec__/merge.spec.d.ts +2 -0
- package/types/auto.d.ts +7 -0
- package/types/decorate.d.ts +24 -0
- package/types/global.d.ts +12 -0
- package/types/index.d.ts +24 -0
- package/types/integrations/MadroneState.d.ts +25 -0
- package/types/integrations/MadroneVue2.d.ts +3 -0
- package/types/integrations/MadroneVue3.d.ts +3 -0
- package/types/integrations/__spec__/madroneState.spec.d.ts +2 -0
- package/types/integrations/__spec__/testAccess.d.ts +2 -0
- package/types/integrations/__spec__/testAll.d.ts +4 -0
- package/types/integrations/__spec__/testAuto.d.ts +2 -0
- package/types/integrations/__spec__/testClass.d.ts +2 -0
- package/types/integrations/__spec__/testVue.d.ts +2 -0
- package/types/integrations/__spec__/vue2.spec.d.ts +2 -0
- package/types/integrations/__spec__/vue3.spec.d.ts +2 -0
- package/types/integrations/index.d.ts +4 -0
- package/types/interfaces.d.ts +27 -0
- package/types/reactivity/Computed.d.ts +8 -0
- package/types/reactivity/Observer.d.ts +50 -0
- package/types/reactivity/Reactive.d.ts +15 -0
- package/types/reactivity/Watcher.d.ts +10 -0
- package/types/reactivity/__spec__/observer.spec.d.ts +2 -0
- package/types/reactivity/__spec__/observer_array.spec.d.ts +2 -0
- package/types/reactivity/__spec__/observer_object.spec.d.ts +2 -0
- package/types/reactivity/__spec__/observer_set.xspec.d.ts +2 -0
- package/types/reactivity/__spec__/reactive.spec.d.ts +2 -0
- package/types/reactivity/__spec__/reactive_array.spec.d.ts +2 -0
- package/types/reactivity/__spec__/reactive_object.spec.d.ts +2 -0
- package/types/reactivity/__spec__/reactive_set.xspec.d.ts +2 -0
- package/types/reactivity/__spec__/watcher.spec.d.ts +2 -0
- package/types/reactivity/global.d.ts +51 -0
- package/types/reactivity/index.d.ts +5 -0
- package/types/reactivity/interfaces.d.ts +28 -0
- package/types/reactivity/typeHandlers.d.ts +20 -0
- package/types/test/util.d.ts +2 -0
- package/types/util.d.ts +32 -0
package/dist/core.umd.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(l,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(l=typeof globalThis<"u"?globalThis:l||self,y(l.madrone={}))})(this,function(l){"use strict";const y=new Set;let te;function Re(){return[...y]}function Pe(){return Re().at(-1)}function ne(){te=Pe()}function re(e){e&&(y.add(e),ne())}function Te(e){y.delete(e),ne()}function C(){return te}const ce=new WeakMap;function V(e){var t;return(((t=C())==null?void 0:t.toRaw)??(()=>e))(e)}function S(e){ce.set(V(e),Date.now())}function Ie(e){return ce.get(V(e))}function _(e,n,t){var a;const r=C();if(!r)throw new Error("No integration specified");typeof t.get=="function"&&(r!=null&&r.defineComputed)?r.defineComputed(e,n,{get:t.get.bind(e),set:(a=t.set)==null?void 0:a.bind(e),enumerable:t.enumerable,configurable:t.configurable,cache:t.cache??!0}):!t.get&&(r!=null&&r.defineProperty)&&r.defineProperty(e,n,{value:t.value,enumerable:t.enumerable,configurable:t.configurable,deep:t.deep})}function ae(e,n){var a,f;const t=Object.getOwnPropertyDescriptors(e),r=(u,d)=>{var h;return(h=n==null?void 0:n[u])==null?void 0:h[d]};for(const[u,d]of Object.entries(t))_(e,u,{get:(a=d.get)==null?void 0:a.bind(e),set:(f=d.set)==null?void 0:f.bind(e),value:r(u,"value")??d.value,enumerable:r(u,"enumerable")??d.enumerable,configurable:r(u,"configurable")??d.configurable,cache:r(u,"cache")??!0,deep:r(u,"deep")??!0});return e}function ue(e,n,t){var a;const r=C();return(a=r==null?void 0:r.watch)==null?void 0:a.call(r,e,n,t)}const N=Symbol("keys"),$=Symbol("computed"),L=new WeakMap,j=new WeakMap,R=new WeakMap,P=new WeakMap;let B=[],W=null;const _e=e=>L.has(e),ie=e=>j.has(e),U=e=>L.get(e),Me=e=>j.get(e),Ee=e=>ie(e)?Me(e):e,Ae=(e,n)=>{L.set(e,n),j.set(n,e)},He=()=>{W===null&&(W=setTimeout(()=>{const e=B;for(B=[];e.length>0;)e.shift()();W=null}))},Ge=e=>{B.push(e),He()},se=(e,n)=>{const t=P.get(e),r=t==null?void 0:t.get(n);if(r){for(const a of r)R.get(a).delete(e);r.clear(),t.delete(n),t.size===0&&P.delete(e)}},fe=(e,n)=>{const t=De();if(!t)return;P.has(t)||P.set(t,new Map),R.has(e)||R.set(e,new Map);const r=R.get(e),a=P.get(t);r.has(n)||r.set(n,new Set),a.has(n)||a.set(n,new Set);const f=r.get(n),u=a.get(n);f.add(t),u.add(e)},de=(e,n)=>{const t=U(e);t&&fe(t,n)},oe=(e,n)=>{const t=R.get(e);if(t!=null&&t.get(n))for(const r of t.get(n))r.setDirty(),se(r,n)},T=(e,n)=>{oe(U(e),n)},Y=[];function De(){return Y.at(-1)}class K{static create(...n){return new K(...n)}constructor(n){this.name=n.name,this.get=n.get,this.set=n.set,this.cache=!!(n.cache??!0),this.alive=!0,this.dirty=!0,this.cachedVal=void 0,this.hooks={onGet:n.onGet,onSet:n.onSet,onChange:n.onChange,onImmediateChange:n.onImmediateChange}}callHook(n){typeof this.hooks[n]=="function"&&this.hooks[n](this)}dispose(){se(this,$),this.alive=!1,this.dirty=!1,this.cachedVal=void 0,this.prev=void 0}wrap(n){Y.push(this);const t=n();return Y.pop(),t}setHook(n,t){this.hooks[n]=t}setDirty(){this.alive&&!this.dirty&&(this.dirty=!0,oe(this,$),this.prev=this.cachedVal,this.callHook("onImmediateChange"),Ge(()=>this.notifyChange()))}notifyChange(){this.callHook("onChange"),this.prev=void 0}run(){if(!this.alive)return;const n=this.wrap(()=>((this.cache&&this.dirty||!this.cache)&&(this.cachedVal=this.get(),this.dirty=!1),this.cachedVal));return fe(this,$),this.callHook("onGet"),n}get value(){return this.run()}set value(n){if(typeof this.set=="function")this.set(n),this.callHook("onSet");else throw new TypeError(`No setter defined for "${this.name}"`)}}function le(...e){return K.create(...e)}function Ve(e){return le(e)}const M=e=>{const{name:n,target:t,key:r,receiver:a,value:f,keysChanged:u=!1,valueChanged:d=!1}=e;return{name:n,target:t,key:r,receiver:a,value:f,keysChanged:u,valueChanged:d}},Ne=(e,n,t,r)=>{var a;de(n,t),(a=e==null?void 0:e.onGet)==null||a.call(e,M({name:e.name,target:n,key:t,receiver:r}))},$e=(e,n,t,r)=>{var h;const a=n[t],f=Array.isArray(n);let u=!1,d=!1;t in n||(T(n,N),d=!0,f&&T(n,"length")),(a!==r||f)&&(T(n,t),u=!0),(d||u)&&((h=e==null?void 0:e.onSet)==null||h.call(e,M({name:e.name,target:n,key:t,value:r,keysChanged:d,valueChanged:u})))},Le=(e,n,t)=>{var r;T(n,t),T(n,N),(r=e==null?void 0:e.onDelete)==null||r.call(e,M({name:e.name,target:n,key:t,keysChanged:!0}))},he=(e,n,t)=>{var r;de(n,N),(r=e==null?void 0:e.onHas)==null||r.call(e,M({name:e.name,target:n,key:t}))};function me(e){const n=e.needsProxy||(()=>!0);return{get:(t,r,a)=>{var u;Ne(e,t,r,a);const f=Reflect.get(t,r,a);return n({target:t,key:r,value:f})&&(e!=null&&e.deep)&&((u=Object.getOwnPropertyDescriptor(t,r))!=null&&u.configurable)?O(f,e):f},set:(t,r,a)=>($e(e,t,r,a),Reflect.set(t,r,a)),deleteProperty:(...t)=>(Le(e,...t),Reflect.deleteProperty(...t)),has:(t,r)=>(he(e,t),Reflect.has(t,r)),ownKeys:t=>(he(e,t),Reflect.ownKeys(t)),getPrototypeOf:t=>Object.getPrototypeOf(t)}}const E=Object.freeze({object:e=>({...me(e)}),array:e=>({...me(e)})});function O(e,n){if(_e(e))return U(e);if(ie(e))return e;const t=n||{},r={...t,deep:(t==null?void 0:t.deep)??!0},a=O.getStringType(e);if(!O.hasHandler(a))return e;const f=new Proxy(e,O.typeHandler(a,r));return Ae(e,f),f}O.getStringType=e=>Object.prototype.toString.call(e).slice(8,-1).toLowerCase(),O.hasHandler=e=>!!E[e],O.typeHandler=(e,n)=>{var t;return(t=E[e])==null?void 0:t.call(E,n)};function X(e,n,t){const r=le({get:e,onChange:({value:f,prev:u})=>n(f,u)}),a=r.run();return t!=null&&t.immediate&&n(a),()=>r.dispose()}function A(e,n,t){var f,u,d,h;let r,a;if(n.cache){const v=Ve({...n,get:n.get,name:e,onImmediateChange:(f=t==null?void 0:t.computed)==null?void 0:f.onImmediateChange,onChange:(u=t==null?void 0:t.computed)==null?void 0:u.onChange,onGet:(d=t==null?void 0:t.computed)==null?void 0:d.onGet,onSet:(h=t==null?void 0:t.computed)==null?void 0:h.onSet});r=function(){return S(this),v.value},a=function(g){v.value=g}}else r=function(){return S(this),n.get.call(this)},a=function(...m){n.set.call(this,...m)};return{enumerable:n.enumerable,configurable:n.configurable,get:r,set:a}}function H(e,n,t){var f,u,d,h,v,m;const r={value:n.value},a=O(r,{name:e,onGet:(f=t==null?void 0:t.reactive)==null?void 0:f.onGet,onHas:(u=t==null?void 0:t.reactive)==null?void 0:u.onHas,onSet:(d=t==null?void 0:t.reactive)==null?void 0:d.onSet,onDelete:(h=t==null?void 0:t.reactive)==null?void 0:h.onDelete,needsProxy:(v=t==null?void 0:t.reactive)==null?void 0:v.needsProxy,deep:n.deep??((m=t==null?void 0:t.reactive)==null?void 0:m.deep)});return{configurable:n.configurable,enumerable:n.enumerable,get:function(){S(this);const{value:b}=a;return Array.isArray(b)&&Reflect.get(b,"length"),b},set:function(b){a.value=b}}}function k(e,n,t,r){Object.defineProperty(e,n,A(n,t,r))}function z(e,n,t,r){Object.defineProperty(e,n,H(n,t,r))}const G={toRaw:Ee,watch:X,describeProperty:H,defineProperty:z,describeComputed:A,defineComputed:k},F=new Set(["__proto__","__ob__"]),I="value";function je(e){const{observable:n,set:t}=e,r=new WeakMap,a=(c,i)=>{let o=r.get(c);o||(o=new Map,r.set(c,o));let w=o.get(i);return w||(w=n({[I]:0}),o.set(i,w)),w},f=t?c=>t(c,I,c[I]+1):c=>{c[I]+=1},u=(c,i)=>{F.has(i)||Reflect.get(a(c,i),I)},d=(c,i)=>{F.has(i)||f(a(c,i))},h=(c,i)=>{const o=r.get(c);o&&d(o,i),r.delete(c)},g={computed:{onGet:c=>{u(c,c.name)},onImmediateChange:c=>{d(c,c.name)}},reactive:{onGet:({target:c,key:i})=>{S(c),u(c,i)},onHas:({target:c,key:i})=>{u(c,i)},onDelete:({target:c,key:i})=>{h(c,i)},onSet:({target:c,key:i,keysChanged:o})=>{d(c,i),o&&d(c)},needsProxy:({key:c})=>!F.has(c)}};function b(c,i){return A(c,i,g)}function x(c,i){return H(c,i,g)}function ee(c,i,o){return k(c,i,o,g)}function s(c,i,o){return z(c,i,o,g)}return{toRaw:G.toRaw,watch:X,describeProperty:x,defineProperty:s,describeComputed:b,defineComputed:ee}}const q=new Set(["__proto__","__ob__"]),Q="value",Be=e=>{e[Q]+=1};function We({reactive:e,toRaw:n}={}){const t=n??(s=>s),r=new WeakMap,a=(s,c)=>{const i=t(s);let o=r.get(i);o||(o=new Map,r.set(i,o));let w=o.get(c);return w||(w=e({[Q]:0}),o.set(c,w)),w},f=(s,c)=>{q.has(c)||Reflect.get(a(s,c),Q)},u=(s,c)=>{q.has(c)||Be(a(s,c))},d=(s,c)=>{const i=t(s),o=r.get(i);o&&u(o,c),r.delete(i)},m={computed:{onGet:s=>{f(s,s.name)},onImmediateChange:s=>{u(s,s.name)}},reactive:{onGet:({target:s,key:c})=>{S(s),f(s,c)},onHas:({target:s,key:c})=>{f(s,c)},onDelete:({target:s,key:c})=>{d(s,c)},onSet:({target:s,key:c,keysChanged:i})=>{u(s,c),i&&u(s)},needsProxy:({key:s})=>!q.has(s)}};function g(s,c){return A(s,c,m)}function b(s,c){return H(s,c,m)}function x(s,c,i){return k(s,c,i,m)}function ee(s,c,i){return z(s,c,i,m)}return{toRaw:G.toRaw,watch:X,describeProperty:b,defineProperty:ee,describeComputed:g,defineComputed:x}}function ge(...e){const n={},t={};for(const r of e){const a=typeof r=="function"?r():r;Object.assign(n,Object.getOwnPropertyDescriptors(a??r??{}))}return Object.defineProperties(t,n),t}function ve(e,n){Object.defineProperties(e.prototype,Object.getOwnPropertyDescriptors(ge(...[...n,e].map(t=>t.prototype))))}const D=new WeakMap;function Ue(...e){return n=>{e!=null&&e.length&&ve(n,e)}}function be(e){D.has(e)||D.set(e,new Set)}function we(e,n){return be(e),D.get(e).has(n)}function Oe(e,n){be(e),D.get(e).add(n)}function ye(e,n,t,r){var f;return C()&&!we(e,n)?(_(e,n,{...t,get:t.get.bind(e),set:(f=t.set)==null?void 0:f.bind(e),enumerable:!0,...r==null?void 0:r.descriptors,cache:!0}),Oe(e,n),!0):!1}function Ce(e,n,t,r){if(typeof t.get=="function"){const a={...t,enumerable:!0,configurable:!0};return a.get=function(){return ye(this,n,t,r),this[n]},a.set=function(u){ye(this,n,t,r),this[n]=u},a}return t}function Se(e,n,t){return Ce(e,n,t)}Se.configure=function(n){return(t,r,a)=>Ce(t,r,a,{descriptors:n})};function J(e,n,t){return C()&&!we(e,n)?(Oe(e,n),_(e,n,{...Object.getOwnPropertyDescriptor(e,n),enumerable:!0,...t==null?void 0:t.descriptors}),!0):!1}function Z(e,n,t){typeof e=="function"?J(e,n):Object.defineProperty(e,n,{configurable:!0,enumerable:!0,get(){if(J(this,n,t))return this[n]},set(r){J(this,n,t)&&(this[n]=r)}})}function p(e,n){return Z(e,n)}p.shallow=function(n,t){return Z(n,t,{descriptors:{deep:!1}})},p.configure=function(n){return(t,r)=>Z(t,r,{descriptors:n})},re(G);const Ye={use:re,unuse:Te,auto:ae,define:_,watch:ue,lastAccessed:Ie};l.MadroneState=G,l.MadroneVue2=je,l.MadroneVue3=We,l.applyClassMixins=ve,l.auto=ae,l.classMixin=Ue,l.computed=Se,l.default=Ye,l.merge=ge,l.reactive=p,l.toRaw=V,l.watch=ue,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@madronejs/core",
|
|
3
|
+
"version": "1.0.16",
|
|
4
|
+
"description": "Object composition and reactivity framework.",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "./dist/core.umd.js",
|
|
7
|
+
"module": "./dist/core.mjs",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/core.mjs",
|
|
12
|
+
"require": "./dist/core.umd.js",
|
|
13
|
+
"types": "./types"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/*.js",
|
|
19
|
+
"dist/*.mjs",
|
|
20
|
+
"types/**/*.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/madronejs/madrone.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/madronejs/madrone/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"registry": "https://registry.npmjs.org/"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"reactivity",
|
|
34
|
+
"composition",
|
|
35
|
+
"state management",
|
|
36
|
+
"madrone",
|
|
37
|
+
"vue"
|
|
38
|
+
],
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/lodash": "^4.14.197",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^6.7.3",
|
|
42
|
+
"@typescript-eslint/parser": "^6.7.3",
|
|
43
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
44
|
+
"eslint": "^8.50.0",
|
|
45
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
46
|
+
"eslint-plugin-import": "^2.28.1",
|
|
47
|
+
"eslint-plugin-unicorn": "^48.0.1",
|
|
48
|
+
"happy-dom": "^12.6.0",
|
|
49
|
+
"lodash": "4.17.21",
|
|
50
|
+
"tsc-alias": "^1.8.7",
|
|
51
|
+
"typedoc": "^0.25.0",
|
|
52
|
+
"typescript": "^4.9.5",
|
|
53
|
+
"vite": "^4.4.10",
|
|
54
|
+
"vitest": "^0.34.6",
|
|
55
|
+
"vue2": "npm:vue@^2.7.14",
|
|
56
|
+
"vue3": "npm:vue@^3.3.4"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": "^18.8",
|
|
60
|
+
"pnpm": "^8.7.0"
|
|
61
|
+
},
|
|
62
|
+
"packageManager": "pnpm@8.7.0",
|
|
63
|
+
"scripts": {
|
|
64
|
+
"lint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
|
|
65
|
+
"test": "vitest",
|
|
66
|
+
"test-ci": "CI=true NODE_ENV=test vitest run --coverage",
|
|
67
|
+
"docs": "typedoc --entryPoints src/index.ts",
|
|
68
|
+
"cleanup": "rm -rf ./dist && rm -rf ./types",
|
|
69
|
+
"cov": "CI=true NODE_ENV=test vitest run --coverage && open coverage/lcov-report/index.html",
|
|
70
|
+
"build": "vite build",
|
|
71
|
+
"build-types": "tsc -p ./tsconfig.types.json && tsc-alias -p tsconfig.types.json",
|
|
72
|
+
"build-all": "pnpm cleanup && pnpm build && pnpm build-types"
|
|
73
|
+
}
|
|
74
|
+
}
|
package/types/auto.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MadroneDescriptor, WatcherOptions } from './interfaces';
|
|
2
|
+
export declare function define<T extends object>(obj: T, key: string, descriptor: MadroneDescriptor): void;
|
|
3
|
+
export declare function auto<T extends object>(obj: T, objDescriptors?: {
|
|
4
|
+
[K in keyof T]?: MadroneDescriptor;
|
|
5
|
+
}): T;
|
|
6
|
+
export declare function watch<T>(scope: () => T, handler: (val: T, old: T) => any, options?: WatcherOptions): () => void;
|
|
7
|
+
//# sourceMappingURL=auto.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DecoratorDescriptorType } from './interfaces';
|
|
2
|
+
export declare function classMixin(...mixins: Array<Function>): (target: Function) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Configure a getter property to be cached
|
|
5
|
+
* @param target The target to add the computed property to
|
|
6
|
+
* @param key The name of the computed property
|
|
7
|
+
* @param descriptor property descriptors
|
|
8
|
+
* @returns the modified property descriptors
|
|
9
|
+
*/
|
|
10
|
+
export declare function computed(target: any, key: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
11
|
+
export declare namespace computed {
|
|
12
|
+
var configure: (descriptorOverrides: DecoratorDescriptorType) => (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Configure a reactive property
|
|
16
|
+
* @param target The target to add the reactive property to
|
|
17
|
+
* @param key The name of the reactive property
|
|
18
|
+
*/
|
|
19
|
+
export declare function reactive(target: any, key: string): void;
|
|
20
|
+
export declare namespace reactive {
|
|
21
|
+
var shallow: (target: any, key: string) => void;
|
|
22
|
+
var configure: (descriptorOverrides: DecoratorDescriptorType) => (target: any, key: string) => void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=decorate.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Integration } from './interfaces';
|
|
2
|
+
export declare function getIntegrations(): Integration[];
|
|
3
|
+
export declare function addIntegration(integration: Integration): void;
|
|
4
|
+
export declare function removeIntegration(integration: any): void;
|
|
5
|
+
export declare function getIntegration(): Integration;
|
|
6
|
+
/** Get the raw value of an object (without the proxy) */
|
|
7
|
+
export declare function toRaw<T>(obj: T): T;
|
|
8
|
+
/** Mark an object as accessed */
|
|
9
|
+
export declare function objectAccessed(obj: object): void;
|
|
10
|
+
/** The last time any reactive property was accessed on a given object */
|
|
11
|
+
export declare function lastAccessed(obj: object): number;
|
|
12
|
+
//# sourceMappingURL=global.d.ts.map
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { addIntegration, removeIntegration, lastAccessed } from './global';
|
|
2
|
+
import { auto, define, watch } from './auto';
|
|
3
|
+
declare const Madrone: {
|
|
4
|
+
/** Configure a global plugin */
|
|
5
|
+
use: typeof addIntegration;
|
|
6
|
+
/** Remove a global plugin */
|
|
7
|
+
unuse: typeof removeIntegration;
|
|
8
|
+
/** Create reactive objects */
|
|
9
|
+
auto: typeof auto;
|
|
10
|
+
/** Define properties on objects */
|
|
11
|
+
define: typeof define;
|
|
12
|
+
/** Watch reactive objects */
|
|
13
|
+
watch: typeof watch;
|
|
14
|
+
/** Get the last time any reactive property was touched on a given object */
|
|
15
|
+
lastAccessed: typeof lastAccessed;
|
|
16
|
+
};
|
|
17
|
+
export default Madrone;
|
|
18
|
+
export * from './integrations';
|
|
19
|
+
export * from './interfaces';
|
|
20
|
+
export * from './decorate';
|
|
21
|
+
export { toRaw } from './global';
|
|
22
|
+
export { merge, applyClassMixins } from './util';
|
|
23
|
+
export { watch, auto } from './auto';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Integration, MadroneComputedDescriptor, MadronePropertyDescriptor } from '../interfaces';
|
|
2
|
+
import { ReactiveOptions } from '../reactivity/interfaces';
|
|
3
|
+
import { ObservableHooksType } from '../reactivity/Observer';
|
|
4
|
+
type MadroneStateOptions<T = any> = {
|
|
5
|
+
reactive?: ReactiveOptions;
|
|
6
|
+
computed?: ObservableHooksType<T>;
|
|
7
|
+
};
|
|
8
|
+
export declare function describeComputed<T = any>(name: string, config: MadroneComputedDescriptor, options?: MadroneStateOptions<T>): {
|
|
9
|
+
enumerable: boolean;
|
|
10
|
+
configurable: boolean;
|
|
11
|
+
get: any;
|
|
12
|
+
set: any;
|
|
13
|
+
};
|
|
14
|
+
export declare function describeProperty(name: string, config: MadronePropertyDescriptor, options?: MadroneStateOptions): {
|
|
15
|
+
configurable: boolean;
|
|
16
|
+
enumerable: boolean;
|
|
17
|
+
get: () => any;
|
|
18
|
+
set: (val: any) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare function defineComputed(target: any, name: string, config: MadroneComputedDescriptor, options: any): void;
|
|
21
|
+
export declare function defineProperty(target: any, name: string, config: MadronePropertyDescriptor, options?: any): void;
|
|
22
|
+
declare const MadroneState: Integration;
|
|
23
|
+
export default MadroneState;
|
|
24
|
+
export { Watcher as watch } from '../reactivity';
|
|
25
|
+
//# sourceMappingURL=MadroneState.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface MadroneDescriptor extends PropertyDescriptor {
|
|
2
|
+
/** Cache a computed property */
|
|
3
|
+
cache?: boolean;
|
|
4
|
+
/** Define a deeply reactive property */
|
|
5
|
+
deep?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export type MadroneComputedDescriptor = Pick<MadroneDescriptor, 'get' | 'set' | 'cache' | 'enumerable' | 'configurable'>;
|
|
8
|
+
export type MadronePropertyDescriptor = Pick<MadroneDescriptor, 'configurable' | 'enumerable' | 'value' | 'deep'>;
|
|
9
|
+
export interface MadroneDescriptorMap {
|
|
10
|
+
[key: string]: MadroneDescriptor;
|
|
11
|
+
}
|
|
12
|
+
export type DecoratorDescriptorType = Omit<MadroneDescriptor, 'get' | 'set' | 'writable' | 'value'>;
|
|
13
|
+
export type DecoratorOptionType = {
|
|
14
|
+
descriptors?: DecoratorDescriptorType;
|
|
15
|
+
};
|
|
16
|
+
export type WatcherOptions = {
|
|
17
|
+
immediate?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export interface Integration {
|
|
20
|
+
defineProperty: (target: any, name: string, config: MadronePropertyDescriptor, options?: any) => any;
|
|
21
|
+
defineComputed: (target: any, name: string, config: MadroneComputedDescriptor, options?: any) => any;
|
|
22
|
+
toRaw?: <T>(target: T) => T;
|
|
23
|
+
watch?: <T>(scope: () => any, handler: (val: T, old?: T) => any, options?: WatcherOptions) => () => void;
|
|
24
|
+
describeComputed?: (name: string, config: MadroneComputedDescriptor, options?: any) => PropertyDescriptor;
|
|
25
|
+
describeProperty?: (name: string, config: MadronePropertyDescriptor, options?: any) => PropertyDescriptor;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ObservableOptions } from './Observer';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new computed instance
|
|
4
|
+
* @param options the computed options
|
|
5
|
+
* @returns the created instance
|
|
6
|
+
*/
|
|
7
|
+
export default function Computed<T>(options: ObservableOptions<T>): import("./Observer").ObservableItem<T>;
|
|
8
|
+
//# sourceMappingURL=Computed.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare function getCurrentObserver(): ObservableItem<any>;
|
|
2
|
+
export declare enum OBSERVER_HOOK {
|
|
3
|
+
onGet = "onGet",
|
|
4
|
+
onSet = "onSet",
|
|
5
|
+
onChange = "onChange",
|
|
6
|
+
onImmediateChange = "onImmediateChange"
|
|
7
|
+
}
|
|
8
|
+
export type ObservableHookType<T> = (obs: ObservableItem<T>) => void;
|
|
9
|
+
export type ObservableHooksType<T> = {
|
|
10
|
+
onGet?: ObservableHookType<T>;
|
|
11
|
+
onSet?: ObservableHookType<T>;
|
|
12
|
+
onChange?: ObservableHookType<T>;
|
|
13
|
+
onImmediateChange?: ObservableHookType<T>;
|
|
14
|
+
};
|
|
15
|
+
export type ObservableOptions<T> = {
|
|
16
|
+
get: () => T;
|
|
17
|
+
name?: string;
|
|
18
|
+
set?: (val: T) => void;
|
|
19
|
+
cache?: boolean;
|
|
20
|
+
} & ObservableHooksType<T>;
|
|
21
|
+
declare class ObservableItem<T> {
|
|
22
|
+
static create<CType>(...args: ConstructorParameters<typeof ObservableItem<CType>>): ObservableItem<CType>;
|
|
23
|
+
constructor(options: ObservableOptions<T>);
|
|
24
|
+
name: string;
|
|
25
|
+
alive: boolean;
|
|
26
|
+
dirty: boolean;
|
|
27
|
+
prev: T;
|
|
28
|
+
cache: boolean;
|
|
29
|
+
private cachedVal;
|
|
30
|
+
private hooks;
|
|
31
|
+
private get;
|
|
32
|
+
private set;
|
|
33
|
+
private callHook;
|
|
34
|
+
/**
|
|
35
|
+
* Stop observing and dispose of the observer
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
38
|
+
dispose(): void;
|
|
39
|
+
private wrap;
|
|
40
|
+
setHook(hook: OBSERVER_HOOK, cb: ObservableHookType<T>): void;
|
|
41
|
+
setDirty(): void;
|
|
42
|
+
private notifyChange;
|
|
43
|
+
run(): T;
|
|
44
|
+
/** The value of the observer */
|
|
45
|
+
get value(): T;
|
|
46
|
+
set value(val: T);
|
|
47
|
+
}
|
|
48
|
+
export { ObservableItem };
|
|
49
|
+
export default function Observer<T = any>(...args: Parameters<typeof ObservableItem.create<T>>): ObservableItem<T>;
|
|
50
|
+
//# sourceMappingURL=Observer.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactiveOptions } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Observe an object
|
|
4
|
+
* @param {Object} target the object to observe
|
|
5
|
+
* @param {Object} options the observation options
|
|
6
|
+
* @returns {Proxy} a proxied version of the object that can be observed
|
|
7
|
+
*/
|
|
8
|
+
declare function Reactive<T extends object>(target: T, options?: ReactiveOptions<T>): T;
|
|
9
|
+
declare namespace Reactive {
|
|
10
|
+
var getStringType: (obj: any) => any;
|
|
11
|
+
var hasHandler: (type: any) => boolean;
|
|
12
|
+
var typeHandler: (type: any, hooks: any) => any;
|
|
13
|
+
}
|
|
14
|
+
export default Reactive;
|
|
15
|
+
//# sourceMappingURL=Reactive.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WatcherOptions } from '../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Watch an observable for changes
|
|
4
|
+
* @param get the getter function returning the item to watch
|
|
5
|
+
* @param handler the callback whenever the value returned from `get` changes
|
|
6
|
+
* @param {Boolean} [options.deep] deeply watch the value
|
|
7
|
+
* @returns a disposer
|
|
8
|
+
*/
|
|
9
|
+
export default function Watcher<T>(get: () => T, handler: (val?: T, old?: T) => any, options?: WatcherOptions): () => void;
|
|
10
|
+
//# sourceMappingURL=Watcher.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ObservableItem } from './Observer';
|
|
2
|
+
export declare const KEYS_SYMBOL: unique symbol;
|
|
3
|
+
export declare const OBSERVER_SYMBOL: unique symbol;
|
|
4
|
+
/** Check if the current target has a proxy associated with it */
|
|
5
|
+
export declare const isReactiveTarget: (target: any) => boolean;
|
|
6
|
+
/** Check if the current proxy has a target object */
|
|
7
|
+
export declare const isReactive: (trk: any) => boolean;
|
|
8
|
+
export declare const getReactive: (target: any) => any;
|
|
9
|
+
export declare const getTarget: (tracker: any) => any;
|
|
10
|
+
export declare const getProxy: (targetOrProxy: any) => any;
|
|
11
|
+
export declare const toRaw: (targetOrProxy: any) => any;
|
|
12
|
+
export declare const getDependencies: (observer: any) => Map<string | symbol | ObservableItem<any>, Set<any>>;
|
|
13
|
+
/** Get the list of items that are observing a given proxy */
|
|
14
|
+
export declare const getObservers: (tracker: any) => Map<string | symbol | ObservableItem<any>, Set<ObservableItem<any>>>;
|
|
15
|
+
export declare const addReactive: (target: any, proxy: any) => void;
|
|
16
|
+
export declare const schedule: (task: any) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Clear all of the current dependencies an observer has
|
|
19
|
+
* @param {Observable} obs the observable to clear it's dependencies
|
|
20
|
+
* @param {String} key the key to clear
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
export declare const observerClear: (obs: ObservableItem<any>, key: string | symbol | ObservableItem<any>) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Make an observer depend on a trackable item
|
|
26
|
+
* @param {trackable} trk the trackable item we're depending on
|
|
27
|
+
* @param {String} key the key to depend on
|
|
28
|
+
* @returns {void}
|
|
29
|
+
*/
|
|
30
|
+
export declare const dependTracker: (trk: object, key: string | symbol | ObservableItem<any>) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Make an observer depend on a raw target
|
|
33
|
+
* @param target the target to depend on
|
|
34
|
+
* @param key the key to depend on
|
|
35
|
+
* @returns {void}
|
|
36
|
+
*/
|
|
37
|
+
export declare const dependTarget: (target: object, key: string | symbol) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Tell all observers of a trackable that the trackable changed
|
|
40
|
+
* @param trk the trackable that changed
|
|
41
|
+
* @param key the key on the trackable that changed
|
|
42
|
+
* @return {void}
|
|
43
|
+
*/
|
|
44
|
+
export declare const trackerChanged: (trk: any, key: any) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Tell all observers listening to this target that this changed
|
|
47
|
+
* @param target the target that changed
|
|
48
|
+
* @param key the key on the trackable that changed
|
|
49
|
+
*/
|
|
50
|
+
export declare const targetChanged: (target: any, key: string | symbol) => void;
|
|
51
|
+
//# sourceMappingURL=global.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type TypeHandlerOptions<T extends object = any> = {
|
|
2
|
+
name?: string;
|
|
3
|
+
deep?: boolean;
|
|
4
|
+
receiver?: any;
|
|
5
|
+
target?: T;
|
|
6
|
+
key?: keyof T;
|
|
7
|
+
value?: T[keyof T];
|
|
8
|
+
keysChanged?: boolean;
|
|
9
|
+
valueChanged?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type HandlerHookType<T extends object = any> = (options: TypeHandlerOptions<T>) => void;
|
|
12
|
+
export type CheckProxyHookType<T extends object = any> = (options: {
|
|
13
|
+
target: T;
|
|
14
|
+
key: keyof T;
|
|
15
|
+
value: T[keyof T];
|
|
16
|
+
}) => boolean;
|
|
17
|
+
export type ReactiveHandlerHooks<T extends object = any> = {
|
|
18
|
+
onGet: HandlerHookType<T>;
|
|
19
|
+
onSet: HandlerHookType<T>;
|
|
20
|
+
onDelete: HandlerHookType<T>;
|
|
21
|
+
onHas: HandlerHookType<T>;
|
|
22
|
+
needsProxy: CheckProxyHookType<T>;
|
|
23
|
+
};
|
|
24
|
+
export type ReactiveOptions<T extends object = any> = {
|
|
25
|
+
name?: any;
|
|
26
|
+
deep?: boolean;
|
|
27
|
+
} & Partial<ReactiveHandlerHooks<T>>;
|
|
28
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare const _default: Readonly<{
|
|
2
|
+
object: (options: any) => {
|
|
3
|
+
get: (target: any, prop: any, receiver: any) => any;
|
|
4
|
+
set: (target: object, propertyKey: PropertyKey, value: any) => boolean;
|
|
5
|
+
deleteProperty: (target: object, propertyKey: PropertyKey) => boolean;
|
|
6
|
+
has: (target: any, key: any) => boolean;
|
|
7
|
+
ownKeys: (target: any) => (string | symbol)[];
|
|
8
|
+
getPrototypeOf: (target: any) => any;
|
|
9
|
+
};
|
|
10
|
+
array: (options: any) => {
|
|
11
|
+
get: (target: any, prop: any, receiver: any) => any;
|
|
12
|
+
set: (target: object, propertyKey: PropertyKey, value: any) => boolean;
|
|
13
|
+
deleteProperty: (target: object, propertyKey: PropertyKey) => boolean;
|
|
14
|
+
has: (target: any, key: any) => boolean;
|
|
15
|
+
ownKeys: (target: any) => (string | symbol)[];
|
|
16
|
+
getPrototypeOf: (target: any) => any;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
export default _default;
|
|
20
|
+
//# sourceMappingURL=typeHandlers.d.ts.map
|
package/types/util.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type OptionalPropertyNames<T> = {
|
|
2
|
+
[K in keyof T]-?: any extends {
|
|
3
|
+
[P in K]: T[K];
|
|
4
|
+
} ? K : never;
|
|
5
|
+
}[keyof T];
|
|
6
|
+
type SpreadProperties<L, R, K extends keyof L & keyof R> = {
|
|
7
|
+
[P in K]: L[P] | Exclude<R[P], undefined>;
|
|
8
|
+
};
|
|
9
|
+
type Id<T> = T extends infer U ? {
|
|
10
|
+
[K in keyof U]: U[K];
|
|
11
|
+
} : never;
|
|
12
|
+
export type SpreadTwo<L, R> = Id<Pick<L, Exclude<keyof L, keyof R>> & Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> & Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> & SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>>;
|
|
13
|
+
export type Spread<A extends readonly [...any]> = A extends [infer L, ...infer R] ? SpreadTwo<L extends (...any: any[]) => any ? ReturnType<L> : L, Spread<R>> : unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Merge multiple object definitions into a single new object definition
|
|
16
|
+
* @param types
|
|
17
|
+
* @returns The new object definition
|
|
18
|
+
*/
|
|
19
|
+
export declare function merge<A extends object[]>(...types: [...A]): Spread<A>;
|
|
20
|
+
/**
|
|
21
|
+
* Extend the prototype of a base class with the prototypes of other classes. Mutates the base class.
|
|
22
|
+
* @param base Base class that the mixins will be mixed into. Any naming conflicts will prefer this base class.
|
|
23
|
+
* @param constructors List of mixin classes that will be applied to the base class.
|
|
24
|
+
*/
|
|
25
|
+
export declare function applyClassMixins(base: any, mixins: [...any]): void;
|
|
26
|
+
export declare function getDefaultDescriptors(obj: any, defaults?: any): {
|
|
27
|
+
[x: string]: TypedPropertyDescriptor<any>;
|
|
28
|
+
} & {
|
|
29
|
+
[x: string]: PropertyDescriptor;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=util.d.ts.map
|