mutts 1.0.0 → 1.0.2
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/README.md +24 -2
- package/dist/chunks/_tslib-C-cuVLvZ.js +73 -0
- package/dist/chunks/_tslib-C-cuVLvZ.js.map +1 -0
- package/dist/chunks/_tslib-CMEnd0VE.esm.js +68 -0
- package/dist/chunks/_tslib-CMEnd0VE.esm.js.map +1 -0
- package/dist/chunks/{decorator-BXsign4Z.js → decorator-D4DU97Zg.js} +70 -4
- package/dist/chunks/decorator-D4DU97Zg.js.map +1 -0
- package/dist/chunks/{decorator-CPbZNnsX.esm.js → decorator-GnHw1Az7.esm.js} +67 -5
- package/dist/chunks/decorator-GnHw1Az7.esm.js.map +1 -0
- package/dist/chunks/index-DBScoeCX.esm.js +1960 -0
- package/dist/chunks/index-DBScoeCX.esm.js.map +1 -0
- package/dist/chunks/index-DOTmXL89.js +1983 -0
- package/dist/chunks/index-DOTmXL89.js.map +1 -0
- package/dist/decorator.d.ts +58 -1
- package/dist/decorator.esm.js +1 -1
- package/dist/decorator.js +1 -1
- package/dist/destroyable.d.ts +42 -0
- package/dist/destroyable.esm.js +19 -1
- package/dist/destroyable.esm.js.map +1 -1
- package/dist/destroyable.js +19 -1
- package/dist/destroyable.js.map +1 -1
- package/dist/eventful.d.ts +10 -1
- package/dist/eventful.esm.js +5 -27
- package/dist/eventful.esm.js.map +1 -1
- package/dist/eventful.js +15 -37
- package/dist/eventful.js.map +1 -1
- package/dist/index.d.ts +52 -3
- package/dist/index.esm.js +3 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/dist/indexable.d.ts +26 -0
- package/dist/indexable.esm.js +6 -0
- package/dist/indexable.esm.js.map +1 -1
- package/dist/indexable.js +6 -0
- package/dist/indexable.js.map +1 -1
- package/dist/mutts.umd.js +1 -1
- package/dist/mutts.umd.js.map +1 -1
- package/dist/mutts.umd.min.js +1 -1
- package/dist/mutts.umd.min.js.map +1 -1
- package/dist/promiseChain.d.ts +10 -0
- package/dist/promiseChain.esm.js +6 -0
- package/dist/promiseChain.esm.js.map +1 -1
- package/dist/promiseChain.js +6 -0
- package/dist/promiseChain.js.map +1 -1
- package/dist/reactive.d.ts +258 -20
- package/dist/reactive.esm.js +4 -1454
- package/dist/reactive.esm.js.map +1 -1
- package/dist/reactive.js +29 -1466
- package/dist/reactive.js.map +1 -1
- package/dist/std-decorators.d.ts +35 -0
- package/dist/std-decorators.esm.js +36 -1
- package/dist/std-decorators.esm.js.map +1 -1
- package/dist/std-decorators.js +36 -1
- package/dist/std-decorators.js.map +1 -1
- package/docs/mixin.md +229 -0
- package/docs/reactive.md +7931 -458
- package/package.json +1 -2
- package/dist/chunks/decorator-BXsign4Z.js.map +0 -1
- package/dist/chunks/decorator-CPbZNnsX.esm.js.map +0 -1
- package/src/decorator.test.ts +0 -495
- package/src/decorator.ts +0 -205
- package/src/destroyable.test.ts +0 -155
- package/src/destroyable.ts +0 -158
- package/src/eventful.test.ts +0 -380
- package/src/eventful.ts +0 -69
- package/src/index.ts +0 -7
- package/src/indexable.test.ts +0 -388
- package/src/indexable.ts +0 -124
- package/src/promiseChain.test.ts +0 -201
- package/src/promiseChain.ts +0 -99
- package/src/reactive/array.test.ts +0 -923
- package/src/reactive/array.ts +0 -352
- package/src/reactive/core.test.ts +0 -1663
- package/src/reactive/core.ts +0 -866
- package/src/reactive/index.ts +0 -28
- package/src/reactive/interface.test.ts +0 -1477
- package/src/reactive/interface.ts +0 -231
- package/src/reactive/map.test.ts +0 -866
- package/src/reactive/map.ts +0 -162
- package/src/reactive/set.test.ts +0 -289
- package/src/reactive/set.ts +0 -142
- package/src/std-decorators.test.ts +0 -679
- package/src/std-decorators.ts +0 -182
- package/src/utils.ts +0 -52
package/src/std-decorators.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { decorator, GenericClassDecorator } from './decorator'
|
|
2
|
-
|
|
3
|
-
// In order to avoid async re-entrance, we could use zone.js or something like that.
|
|
4
|
-
const syncCalculating: { object: object; prop: PropertyKey }[] = []
|
|
5
|
-
export const cached = decorator({
|
|
6
|
-
getter(original, propertyKey) {
|
|
7
|
-
return function (this: any) {
|
|
8
|
-
const alreadyCalculating = syncCalculating.findIndex(
|
|
9
|
-
(c) => c.object === this && c.prop === propertyKey
|
|
10
|
-
)
|
|
11
|
-
if (alreadyCalculating > -1)
|
|
12
|
-
throw new Error(
|
|
13
|
-
`Circular dependency detected: ${syncCalculating
|
|
14
|
-
.slice(alreadyCalculating)
|
|
15
|
-
.map((c) => `${c.object.constructor.name}.${String(c.prop)}`)
|
|
16
|
-
.join(' -> ')} -> again`
|
|
17
|
-
)
|
|
18
|
-
syncCalculating.push({ object: this, prop: propertyKey })
|
|
19
|
-
try {
|
|
20
|
-
const rv = original.call(this)
|
|
21
|
-
cache(this, propertyKey, rv)
|
|
22
|
-
return rv
|
|
23
|
-
} finally {
|
|
24
|
-
syncCalculating.pop()
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
export function isCached(object: Object, propertyKey: PropertyKey) {
|
|
31
|
-
return !!Object.getOwnPropertyDescriptor(object, propertyKey)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function cache(object: Object, propertyKey: PropertyKey, value: any) {
|
|
35
|
-
Object.defineProperty(object, propertyKey, { value })
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function describe(descriptor: {
|
|
39
|
-
enumerable?: boolean
|
|
40
|
-
configurable?: boolean // Not modifiable once the property has been defined ?
|
|
41
|
-
writable?: boolean
|
|
42
|
-
}) {
|
|
43
|
-
return <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>
|
|
44
|
-
(Base) => {
|
|
45
|
-
return class extends Base {
|
|
46
|
-
constructor(...args: any[]) {
|
|
47
|
-
super(...args)
|
|
48
|
-
for (const key of properties) {
|
|
49
|
-
Object.defineProperty(this, key, {
|
|
50
|
-
...Object.getOwnPropertyDescriptor(this, key),
|
|
51
|
-
...descriptor,
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const deprecated = Object.assign(
|
|
60
|
-
decorator({
|
|
61
|
-
method(original, propertyKey) {
|
|
62
|
-
return function (this: any, ...args: any[]) {
|
|
63
|
-
deprecated.warn(this, propertyKey)
|
|
64
|
-
return original.apply(this, args)
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
getter(original, propertyKey) {
|
|
68
|
-
return function (this: any) {
|
|
69
|
-
deprecated.warn(this, propertyKey)
|
|
70
|
-
return original.call(this)
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
setter(original, propertyKey) {
|
|
74
|
-
return function (this: any, value: any) {
|
|
75
|
-
deprecated.warn(this, propertyKey)
|
|
76
|
-
return original.call(this, value)
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
class(original) {
|
|
80
|
-
return class extends original {
|
|
81
|
-
constructor(...args: any[]) {
|
|
82
|
-
super(...args)
|
|
83
|
-
deprecated.warn(this, 'constructor')
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
default(message: string) {
|
|
88
|
-
return decorator({
|
|
89
|
-
method(original, propertyKey) {
|
|
90
|
-
return function (this: any, ...args: any[]) {
|
|
91
|
-
deprecated.warn(this, propertyKey, message)
|
|
92
|
-
return original.apply(this, args)
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
getter(original, propertyKey) {
|
|
96
|
-
return function (this: any) {
|
|
97
|
-
deprecated.warn(this, propertyKey, message)
|
|
98
|
-
return original.call(this)
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
setter(original, propertyKey) {
|
|
102
|
-
return function (this: any, value: any) {
|
|
103
|
-
deprecated.warn(this, propertyKey, message)
|
|
104
|
-
return original.call(this, value)
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
class(original) {
|
|
108
|
-
return class extends original {
|
|
109
|
-
constructor(...args: any[]) {
|
|
110
|
-
super(...args)
|
|
111
|
-
deprecated.warn(this, 'constructor', message)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
})
|
|
116
|
-
},
|
|
117
|
-
}),
|
|
118
|
-
{
|
|
119
|
-
warn: (target: any, propertyKey: PropertyKey, message?: string) => {
|
|
120
|
-
// biome-ignore lint/suspicious/noConsole: To be overridden
|
|
121
|
-
console.warn(
|
|
122
|
-
`${target.constructor.name}.${String(propertyKey)} is deprecated${message ? `: ${message}` : ''}`
|
|
123
|
-
)
|
|
124
|
-
},
|
|
125
|
-
}
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
export function debounce(delay: number) {
|
|
129
|
-
return decorator({
|
|
130
|
-
method(original, _propertyKey) {
|
|
131
|
-
let timeoutId: ReturnType<typeof setTimeout> | null = null
|
|
132
|
-
|
|
133
|
-
return function (this: any, ...args: any[]) {
|
|
134
|
-
// Clear existing timeout
|
|
135
|
-
if (timeoutId) {
|
|
136
|
-
clearTimeout(timeoutId)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Set new timeout
|
|
140
|
-
timeoutId = setTimeout(() => {
|
|
141
|
-
original.apply(this, args)
|
|
142
|
-
timeoutId = null
|
|
143
|
-
}, delay)
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function throttle(delay: number) {
|
|
150
|
-
return decorator({
|
|
151
|
-
method(original, _propertyKey) {
|
|
152
|
-
let lastCallTime = 0
|
|
153
|
-
let timeoutId: ReturnType<typeof setTimeout> | null = null
|
|
154
|
-
|
|
155
|
-
return function (this: any, ...args: any[]) {
|
|
156
|
-
const now = Date.now()
|
|
157
|
-
|
|
158
|
-
// If enough time has passed since last call, execute immediately
|
|
159
|
-
if (now - lastCallTime >= delay) {
|
|
160
|
-
// Clear any pending timeout since we're executing now
|
|
161
|
-
if (timeoutId) {
|
|
162
|
-
clearTimeout(timeoutId)
|
|
163
|
-
timeoutId = null
|
|
164
|
-
}
|
|
165
|
-
lastCallTime = now
|
|
166
|
-
return original.apply(this, args)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Otherwise, schedule execution for when the delay period ends
|
|
170
|
-
if (!timeoutId) {
|
|
171
|
-
const remainingTime = delay - (now - lastCallTime)
|
|
172
|
-
const scheduledArgs = [...args] // Capture args at scheduling time
|
|
173
|
-
timeoutId = setTimeout(() => {
|
|
174
|
-
lastCallTime = Date.now()
|
|
175
|
-
original.apply(this, scheduledArgs)
|
|
176
|
-
timeoutId = null
|
|
177
|
-
}, remainingTime)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
})
|
|
182
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
type ElementTypes<T extends readonly unknown[]> = {
|
|
2
|
-
[K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K]
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function zip<T extends (readonly unknown[])[]>(...args: T): ElementTypes<T>[] {
|
|
6
|
-
if (!args.length) return []
|
|
7
|
-
const minLength = Math.min(...args.map((arr) => arr.length))
|
|
8
|
-
const result: ElementTypes<T>[] = []
|
|
9
|
-
|
|
10
|
-
for (let i = 0; i < minLength; i++) {
|
|
11
|
-
const tuple = args.map((arr) => arr[i]) as ElementTypes<T>
|
|
12
|
-
result.push(tuple)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return result
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const nativeConstructors = new Set<Function>([
|
|
19
|
-
Object,
|
|
20
|
-
Array,
|
|
21
|
-
Date,
|
|
22
|
-
Function,
|
|
23
|
-
Set,
|
|
24
|
-
Map,
|
|
25
|
-
WeakMap,
|
|
26
|
-
WeakSet,
|
|
27
|
-
Promise,
|
|
28
|
-
Error,
|
|
29
|
-
TypeError,
|
|
30
|
-
ReferenceError,
|
|
31
|
-
SyntaxError,
|
|
32
|
-
RangeError,
|
|
33
|
-
URIError,
|
|
34
|
-
EvalError,
|
|
35
|
-
Reflect,
|
|
36
|
-
Proxy,
|
|
37
|
-
RegExp,
|
|
38
|
-
String,
|
|
39
|
-
Number,
|
|
40
|
-
Boolean,
|
|
41
|
-
] as Function[])
|
|
42
|
-
export function isConstructor(fn: Function): boolean {
|
|
43
|
-
return fn && (nativeConstructors.has(fn) || fn.toString().startsWith('class '))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function renamed<F extends Function>(fct: F, name: string): F {
|
|
47
|
-
return Object.defineProperties(fct, {
|
|
48
|
-
name: {
|
|
49
|
-
value: name,
|
|
50
|
-
},
|
|
51
|
-
})
|
|
52
|
-
}
|