@jay-framework/component 0.22.2 → 0.23.1
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/dist/index.d.ts +1 -1
- package/dist/index.js +17 -34
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JayElement, ContextMarker, PreRenderElement,
|
|
1
|
+
import { JayElement, JayComponent, ContextMarker, PreRenderElement, EventEmitter } from '@jay-framework/runtime';
|
|
2
2
|
import { Getter, Reactive, ValueOrGetter, Setter } from '@jay-framework/reactive';
|
|
3
3
|
import { JSONPatch } from '@jay-framework/json-patch';
|
|
4
4
|
import { HTMLElement } from 'node-html-parser';
|
package/dist/index.js
CHANGED
|
@@ -16,12 +16,10 @@ function newContextProxy(reactive, context) {
|
|
|
16
16
|
};
|
|
17
17
|
return new Proxy(context, {
|
|
18
18
|
get(target, p, receiver) {
|
|
19
|
-
if (p === CONTEXT_REACTIVE_SYMBOL_CONTEXT)
|
|
20
|
-
return reactive;
|
|
19
|
+
if (p === CONTEXT_REACTIVE_SYMBOL_CONTEXT) return reactive;
|
|
21
20
|
else if (!target[p][GetterMark] && !target[p][SetterMark] && typeof target[p] === "function")
|
|
22
21
|
return wrap(target[p]);
|
|
23
|
-
else
|
|
24
|
-
return target[p];
|
|
22
|
+
else return target[p];
|
|
25
23
|
}
|
|
26
24
|
});
|
|
27
25
|
}
|
|
@@ -54,10 +52,8 @@ function createEffect(effect) {
|
|
|
54
52
|
const mounted = currentHookContext().mountedSignal[0];
|
|
55
53
|
currentHookContext().reactive.createReaction(() => {
|
|
56
54
|
if (lastMounted !== mounted()) {
|
|
57
|
-
if (mounted())
|
|
58
|
-
|
|
59
|
-
else
|
|
60
|
-
clean();
|
|
55
|
+
if (mounted()) cleanup = effect();
|
|
56
|
+
else clean();
|
|
61
57
|
lastMounted = mounted();
|
|
62
58
|
} else if (mounted()) {
|
|
63
59
|
clean();
|
|
@@ -108,8 +104,7 @@ function mapItem(item, index, length, force, cached, mapCallback) {
|
|
|
108
104
|
usedIndex: indexGetter.wasUsed(),
|
|
109
105
|
usedLength: lengthGetter.wasUsed()
|
|
110
106
|
};
|
|
111
|
-
} else
|
|
112
|
-
return cached;
|
|
107
|
+
} else return cached;
|
|
113
108
|
}
|
|
114
109
|
function createDerivedArray(arrayGetter, mapCallback) {
|
|
115
110
|
let [sourceArray] = currentHookContext().reactive.createSignal(
|
|
@@ -147,16 +142,13 @@ function createEvent(eventEffect) {
|
|
|
147
142
|
handlers.push(h);
|
|
148
143
|
};
|
|
149
144
|
emitter.emit = (event) => {
|
|
150
|
-
for (const h of handlers)
|
|
151
|
-
h({ event });
|
|
145
|
+
for (const h of handlers) h({ event });
|
|
152
146
|
};
|
|
153
147
|
emitter.remove = (h) => {
|
|
154
148
|
const idx = handlers.indexOf(h);
|
|
155
|
-
if (idx >= 0)
|
|
156
|
-
handlers.splice(idx, 1);
|
|
149
|
+
if (idx >= 0) handlers.splice(idx, 1);
|
|
157
150
|
};
|
|
158
|
-
if (eventEffect)
|
|
159
|
-
createEffect(() => eventEffect(emitter));
|
|
151
|
+
if (eventEffect) createEffect(() => eventEffect(emitter));
|
|
160
152
|
return emitter;
|
|
161
153
|
}
|
|
162
154
|
function provideContext(marker, context) {
|
|
@@ -171,8 +163,7 @@ function materializeViewState(vsValueOrGetter) {
|
|
|
171
163
|
let vs = {};
|
|
172
164
|
for (let key in vsValueOrGetter) {
|
|
173
165
|
let value = vsValueOrGetter[key];
|
|
174
|
-
if (typeof value === "function")
|
|
175
|
-
value = value();
|
|
166
|
+
if (typeof value === "function") value = value();
|
|
176
167
|
vs[key] = value;
|
|
177
168
|
}
|
|
178
169
|
return vs;
|
|
@@ -191,10 +182,8 @@ function renderWithContexts(provideContexts, render, viewState, index = 0) {
|
|
|
191
182
|
function mkMounts(componentContext, element) {
|
|
192
183
|
const [mounted, setMounted] = componentContext.mountedSignal;
|
|
193
184
|
componentContext.reactive.createReaction(() => {
|
|
194
|
-
if (mounted)
|
|
195
|
-
|
|
196
|
-
else
|
|
197
|
-
element.unmount();
|
|
185
|
+
if (mounted) element.mount();
|
|
186
|
+
else element.unmount();
|
|
198
187
|
});
|
|
199
188
|
const mount = () => {
|
|
200
189
|
componentContext.reactive.enable();
|
|
@@ -248,8 +237,7 @@ function makeJayComponent(preRender, comp, ...contextMarkers) {
|
|
|
248
237
|
render,
|
|
249
238
|
viewState
|
|
250
239
|
);
|
|
251
|
-
else
|
|
252
|
-
element.update(viewState);
|
|
240
|
+
else element.update(viewState);
|
|
253
241
|
viewStateChangeListener?.({ event: viewState, viewState, coordinate: [] });
|
|
254
242
|
});
|
|
255
243
|
const [mount, unmount] = mkMounts(componentContext, element);
|
|
@@ -304,24 +292,19 @@ function makePropsProxy(reactive, props) {
|
|
|
304
292
|
for (const prop in newProps) {
|
|
305
293
|
if (!stateMap.hasOwnProperty(prop))
|
|
306
294
|
stateMap[prop] = reactive.createSignal(newProps[prop]);
|
|
307
|
-
else
|
|
308
|
-
stateMap[prop][1](newProps[prop]);
|
|
295
|
+
else stateMap[prop][1](newProps[prop]);
|
|
309
296
|
}
|
|
310
297
|
});
|
|
311
298
|
};
|
|
312
299
|
const getter = (obj, prop) => {
|
|
313
|
-
if (!stateMap.hasOwnProperty(prop))
|
|
314
|
-
stateMap[prop] = reactive.createSignal(obj[prop]);
|
|
300
|
+
if (!stateMap.hasOwnProperty(prop)) stateMap[prop] = reactive.createSignal(obj[prop]);
|
|
315
301
|
return stateMap[prop][0];
|
|
316
302
|
};
|
|
317
303
|
return new Proxy(props, {
|
|
318
304
|
get: function(obj, prop) {
|
|
319
|
-
if (prop === "update")
|
|
320
|
-
|
|
321
|
-
else
|
|
322
|
-
return _props;
|
|
323
|
-
else
|
|
324
|
-
return getter(obj, prop);
|
|
305
|
+
if (prop === "update") return update;
|
|
306
|
+
else if (prop === "props") return _props;
|
|
307
|
+
else return getter(obj, prop);
|
|
325
308
|
}
|
|
326
309
|
});
|
|
327
310
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"test:watch": "vitest"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@jay-framework/json-patch": "^0.
|
|
25
|
-
"@jay-framework/reactive": "^0.
|
|
26
|
-
"@jay-framework/runtime": "^0.
|
|
24
|
+
"@jay-framework/json-patch": "^0.23.1",
|
|
25
|
+
"@jay-framework/reactive": "^0.23.1",
|
|
26
|
+
"@jay-framework/runtime": "^0.23.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@jay-framework/dev-environment": "^0.
|
|
29
|
+
"@jay-framework/dev-environment": "^0.23.1",
|
|
30
30
|
"@testing-library/jest-dom": "^6.2.0",
|
|
31
31
|
"@types/node": "^20.11.5",
|
|
32
32
|
"rimraf": "^5.0.5",
|