@devvit/ui-renderer 0.10.19-next-2024-04-17-91fc3e40d.0 → 0.10.19-next-2024-04-18-58e48dd7c.0
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/client/devvit-custom-post.d.ts +2 -2
- package/client/devvit-custom-post.js +31 -31
- package/client/{app-ui-looper.d.ts → dispatcher.d.ts} +2 -2
- package/client/dispatcher.d.ts.map +1 -0
- package/client/{app-ui-looper.js → dispatcher.js} +46 -46
- package/client/dispatcher.test.d.ts.map +1 -0
- package/package.json +8 -8
- package/client/app-ui-looper.d.ts.map +0 -1
- package/client/app-ui-looper.test.d.ts.map +0 -1
|
@@ -52,8 +52,8 @@ export type DevvitUserActionEvent = FaceplateEvent<'devvit-user-action'> & {
|
|
|
52
52
|
* Assumes the loaded program is a CustomPost & UIEventHandler.
|
|
53
53
|
*
|
|
54
54
|
* The complexity of this class should only be the UI itself and proxying state
|
|
55
|
-
* to devvit-blocks-renderer and
|
|
56
|
-
*
|
|
55
|
+
* to devvit-blocks-renderer and Dispatcher. Don't put logic here that you can't
|
|
56
|
+
* unit test.
|
|
57
57
|
*
|
|
58
58
|
* @slot - Loading / unloaded state.
|
|
59
59
|
*/
|
|
@@ -18,7 +18,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
18
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
19
19
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20
20
|
};
|
|
21
|
-
var _DevvitCustomPost_instances, _DevvitCustomPost_lastRequest,
|
|
21
|
+
var _DevvitCustomPost_instances, _DevvitCustomPost_lastRequest, _DevvitCustomPost_dispatcher, _DevvitCustomPost_rootHeight, _DevvitCustomPost_resizeObserver, _DevvitCustomPost_bubble, _DevvitCustomPost_newRenderContext, _DevvitCustomPost_onError, _DevvitCustomPost_onPluginCall, _DevvitCustomPost_onRenderPost, _DevvitCustomPost_onUserActionEffect, _DevvitCustomPost_onUserActionEvent;
|
|
22
22
|
import '@reddit/faceplate-ui/templateRenderingStrategy/clientStrategy.js';
|
|
23
23
|
import { Block, BlockConfig_Root, BlockRenderEventType, BlockStackDirection, Dimensions, RealtimeDefinition, } from '@devvit/protos';
|
|
24
24
|
import { isCircuitBreaker } from '@devvit/runtime-lite/types/CircuitBreaker.js';
|
|
@@ -31,7 +31,7 @@ import { customElement, property, query, state } from 'lit/decorators.js';
|
|
|
31
31
|
import { DevvitBlocksRenderer } from '../blocks/components/devvit-blocks-renderer.js';
|
|
32
32
|
import { DEFAULT_ROOT_HEIGHT } from '../blocks/templates/renderBlock.js';
|
|
33
33
|
import { styles } from '../styles.js';
|
|
34
|
-
import {
|
|
34
|
+
import { Dispatcher } from './dispatcher.js';
|
|
35
35
|
import { RemoteApp } from './ui-app.js';
|
|
36
36
|
import '../blocks/components/devvit-blocks-renderer.js';
|
|
37
37
|
import '../blocks/components/devvit-blocks-webview.js';
|
|
@@ -42,8 +42,8 @@ import './devvit-animation-player.js';
|
|
|
42
42
|
* Assumes the loaded program is a CustomPost & UIEventHandler.
|
|
43
43
|
*
|
|
44
44
|
* The complexity of this class should only be the UI itself and proxying state
|
|
45
|
-
* to devvit-blocks-renderer and
|
|
46
|
-
*
|
|
45
|
+
* to devvit-blocks-renderer and Dispatcher. Don't put logic here that you can't
|
|
46
|
+
* unit test.
|
|
47
47
|
*
|
|
48
48
|
* @slot - Loading / unloaded state.
|
|
49
49
|
*/
|
|
@@ -61,15 +61,15 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
|
|
|
61
61
|
this.useSandbox = true;
|
|
62
62
|
this._isSuspended = false; // eslint-disable-line @typescript-eslint/naming-convention
|
|
63
63
|
_DevvitCustomPost_lastRequest.set(this, void 0);
|
|
64
|
-
|
|
64
|
+
_DevvitCustomPost_dispatcher.set(this, new Dispatcher());
|
|
65
65
|
_DevvitCustomPost_rootHeight.set(this, void 0);
|
|
66
66
|
_DevvitCustomPost_resizeObserver.set(this, void 0);
|
|
67
67
|
_DevvitCustomPost_newRenderContext.set(this, () => ({
|
|
68
68
|
experimental: this.useExperimentalBlocks,
|
|
69
|
-
onAction: (action) => __classPrivateFieldGet(this,
|
|
69
|
+
onAction: (action) => __classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").queueRenderPost(BlockRenderEventType.RENDER_USER_ACTION, action.id, action.data ?? {}),
|
|
70
70
|
request: __classPrivateFieldGet(this, _DevvitCustomPost_lastRequest, "f"),
|
|
71
71
|
stackDirection: BlockStackDirection.UNRECOGNIZED,
|
|
72
|
-
state: __classPrivateFieldGet(this,
|
|
72
|
+
state: __classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").appState,
|
|
73
73
|
}));
|
|
74
74
|
_DevvitCustomPost_onError.set(this, (type, err) => {
|
|
75
75
|
if (!isCircuitBreaker(err))
|
|
@@ -101,17 +101,17 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
|
|
|
101
101
|
_DevvitCustomPost_onUserActionEffect.set(this, (fx) => {
|
|
102
102
|
__classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_bubble).call(this, 'devvit-ui-effect', {
|
|
103
103
|
effect: fx,
|
|
104
|
-
onEvent: (ev) => __classPrivateFieldGet(this,
|
|
104
|
+
onEvent: (ev) => __classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").queueEvent(ev),
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
_DevvitCustomPost_onUserActionEvent.set(this, (ev) => {
|
|
108
|
-
__classPrivateFieldGet(this,
|
|
108
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").queueRenderPost(BlockRenderEventType.RENDER_USER_ACTION, ev.detail.action.id, ev.detail.action.data);
|
|
109
109
|
});
|
|
110
110
|
this.addEventListener('devvit-user-action', __classPrivateFieldGet(this, _DevvitCustomPost_onUserActionEvent, "f"));
|
|
111
|
-
__classPrivateFieldGet(this,
|
|
112
|
-
__classPrivateFieldGet(this,
|
|
113
|
-
__classPrivateFieldGet(this,
|
|
114
|
-
__classPrivateFieldGet(this,
|
|
111
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").onError = __classPrivateFieldGet(this, _DevvitCustomPost_onError, "f");
|
|
112
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").onPluginCall = __classPrivateFieldGet(this, _DevvitCustomPost_onPluginCall, "f");
|
|
113
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").onRenderPost = __classPrivateFieldGet(this, _DevvitCustomPost_onRenderPost, "f");
|
|
114
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").onUserAction = __classPrivateFieldGet(this, _DevvitCustomPost_onUserActionEffect, "f");
|
|
115
115
|
}
|
|
116
116
|
get blocksConfig() {
|
|
117
117
|
if (!this._rootBlock)
|
|
@@ -133,7 +133,7 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
|
|
|
133
133
|
}
|
|
134
134
|
disconnectedCallback() {
|
|
135
135
|
this._isSuspended = true;
|
|
136
|
-
__classPrivateFieldGet(this,
|
|
136
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").unload();
|
|
137
137
|
__classPrivateFieldGet(this, _DevvitCustomPost_resizeObserver, "f")?.unobserve(this);
|
|
138
138
|
__classPrivateFieldGet(this, _DevvitCustomPost_resizeObserver, "f")?.disconnect();
|
|
139
139
|
super.disconnectedCallback();
|
|
@@ -161,35 +161,35 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
|
|
|
161
161
|
</div>`;
|
|
162
162
|
}
|
|
163
163
|
async willUpdate(props) {
|
|
164
|
-
__classPrivateFieldGet(this,
|
|
165
|
-
__classPrivateFieldGet(this,
|
|
166
|
-
// If the custom post has dimensions, set them on all prop updates to keep
|
|
167
|
-
// to date on what's happening.
|
|
164
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").meta = this.metadata;
|
|
165
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").postConfig = this.postConfig;
|
|
166
|
+
// If the custom post has dimensions, set them on all prop updates to keep
|
|
167
|
+
// the dispatcher up to date on what's happening.
|
|
168
168
|
if (this.dimensions) {
|
|
169
|
-
__classPrivateFieldGet(this,
|
|
169
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").dimensions = this.dimensions;
|
|
170
170
|
}
|
|
171
171
|
if (props.has('postId')) {
|
|
172
|
-
__classPrivateFieldGet(this,
|
|
172
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").postID = this.postId ? asT3ID(this.postId) : undefined;
|
|
173
173
|
}
|
|
174
174
|
if (props.has('runtimeDebugLogging')) {
|
|
175
|
-
__classPrivateFieldGet(this,
|
|
175
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").runtimeDebugLogging = this.runtimeDebugLogging;
|
|
176
176
|
}
|
|
177
177
|
if (props.has('actorRef')) {
|
|
178
178
|
if (!this.actorRef)
|
|
179
|
-
__classPrivateFieldGet(this,
|
|
179
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").remote = undefined;
|
|
180
180
|
else if ('As' in this.actorRef)
|
|
181
|
-
__classPrivateFieldGet(this,
|
|
181
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").remote = new RemoteApp(this.actorRef); // to-do: delete ActorRef.
|
|
182
182
|
else
|
|
183
|
-
__classPrivateFieldGet(this,
|
|
183
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").remote = this.actorRef;
|
|
184
184
|
}
|
|
185
185
|
if (props.has('localRuntimeCode'))
|
|
186
|
-
__classPrivateFieldGet(this,
|
|
186
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").setLocalSrc(this.localRuntimeCode);
|
|
187
187
|
if (props.has('bundle') && this.bundle) {
|
|
188
|
-
await __classPrivateFieldGet(this,
|
|
188
|
+
await __classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").load(this.bundle, this.useSandbox);
|
|
189
189
|
if (props.get('bundle')) {
|
|
190
190
|
// Bundle was _replaced_ (likely devvit-preview). Require a new render.
|
|
191
191
|
this.renderResponse = undefined;
|
|
192
|
-
__classPrivateFieldGet(this,
|
|
192
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").resetAppState();
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
// If the custom post does not have dimensions, block all render events until they are
|
|
@@ -204,16 +204,16 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
|
|
|
204
204
|
// We always want to trigger at least one render if:
|
|
205
205
|
// 1. The app dimensions change
|
|
206
206
|
// 2. The bundle changes. Loading a bundle is lengthy and dimensions may have changed during a load
|
|
207
|
-
if (!__classPrivateFieldGet(this,
|
|
208
|
-
__classPrivateFieldGet(this,
|
|
207
|
+
if (!__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").rendered) {
|
|
208
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").queueRenderPost(BlockRenderEventType.RENDER_INITIAL, undefined, {});
|
|
209
209
|
}
|
|
210
210
|
else if (props.has('dimensions') || props.has('bundle')) {
|
|
211
|
-
__classPrivateFieldGet(this,
|
|
211
|
+
__classPrivateFieldGet(this, _DevvitCustomPost_dispatcher, "f").queueRenderPost(BlockRenderEventType.RENDER_USER_ACTION, undefined, {});
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
};
|
|
215
215
|
_DevvitCustomPost_lastRequest = new WeakMap();
|
|
216
|
-
|
|
216
|
+
_DevvitCustomPost_dispatcher = new WeakMap();
|
|
217
217
|
_DevvitCustomPost_rootHeight = new WeakMap();
|
|
218
218
|
_DevvitCustomPost_resizeObserver = new WeakMap();
|
|
219
219
|
_DevvitCustomPost_newRenderContext = new WeakMap();
|
|
@@ -28,7 +28,7 @@ type EventData = {
|
|
|
28
28
|
* not to show any issues. A bundle or runtime can be replaced on the fly with
|
|
29
29
|
* losing state.
|
|
30
30
|
*/
|
|
31
|
-
export declare class
|
|
31
|
+
export declare class Dispatcher {
|
|
32
32
|
#private;
|
|
33
33
|
meta?: Metadata | undefined;
|
|
34
34
|
onError?: ErrorCallback | undefined;
|
|
@@ -68,4 +68,4 @@ export declare class AppUILooper {
|
|
|
68
68
|
unload(): void;
|
|
69
69
|
}
|
|
70
70
|
export {};
|
|
71
|
-
//# sourceMappingURL=
|
|
71
|
+
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../library/src/client/dispatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,MAAM,EAGN,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,EACN,OAAO,EACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAsB,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EAEX,MAAM,kDAAkD,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAGlF,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAG7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAQzC,KAAK,QAAQ,GAAG;IACd,UAAU,CAAC,EAAE;QACX,OAAO,EAAE,GAAG,GAAG,SAAS,CAAC;QACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;KACtC,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AACF,KAAK,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE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AAG,EAAE,IAAI,GAAG,SAAS,GAAG,IAAI;IAWxC,mDAAmD;IACnD,MAAM,IAAI,IAAI;CAiHf"}
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var
|
|
12
|
+
var _Dispatcher_instances, _Dispatcher_app, _Dispatcher_appState, _Dispatcher_q, _Dispatcher_rendered, _Dispatcher_rerenderTimeout, _Dispatcher_runtimeDebugLogging, _Dispatcher_onEffects, _Dispatcher_onError, _Dispatcher_onPluginCall, _Dispatcher_processEvent, _Dispatcher_renderPost;
|
|
13
13
|
import { BlockRenderEventType, RealtimeDefinition } from '@devvit/protos';
|
|
14
14
|
import { BrowserLiteClient } from '@devvit/runtime-lite/client/BrowserLiteClient.js';
|
|
15
15
|
import { isCircuitBreaker } from '@devvit/runtime-lite/types/CircuitBreaker.js';
|
|
@@ -33,16 +33,16 @@ initDevvitGlobal();
|
|
|
33
33
|
* not to show any issues. A bundle or runtime can be replaced on the fly with
|
|
34
34
|
* losing state.
|
|
35
35
|
*/
|
|
36
|
-
export class
|
|
36
|
+
export class Dispatcher {
|
|
37
37
|
constructor() {
|
|
38
|
-
|
|
38
|
+
_Dispatcher_instances.add(this);
|
|
39
39
|
/** Dimensions that describe layout information for the custom post entry point */
|
|
40
40
|
this.dimensions = DEFAULT_DIMENSIONS;
|
|
41
41
|
/**
|
|
42
42
|
* Bundle currently loaded. Used to test whether failed requests are for the
|
|
43
43
|
* currently loaded bundle or a previous one.
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
_Dispatcher_app.set(this, void 0);
|
|
46
46
|
/**
|
|
47
47
|
* App state is never reset in production. Prior remote executions may have
|
|
48
48
|
* occurred. The next loop will replace the state. Do not lose the current
|
|
@@ -50,18 +50,18 @@ export class AppUILooper {
|
|
|
50
50
|
* only time state should be reinitialized is when a bundle has been
|
|
51
51
|
* _replaced_ such as by devvit-preview.
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
_Dispatcher_appState.set(this, {});
|
|
54
54
|
/** No concurrency is used to enforce order. to-do: replace with array? */
|
|
55
|
-
|
|
55
|
+
_Dispatcher_q.set(this, new PQueue({ concurrency: 1 }));
|
|
56
56
|
/**
|
|
57
57
|
* True if app has rendered since loaded. Since a successful render isn't
|
|
58
58
|
* known at queue time, it's possible for multiple redundant renders to be
|
|
59
59
|
* enqueued.
|
|
60
60
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
_Dispatcher_rendered.set(this, false);
|
|
62
|
+
_Dispatcher_rerenderTimeout.set(this, void 0);
|
|
63
|
+
_Dispatcher_runtimeDebugLogging.set(this, false);
|
|
64
|
+
_Dispatcher_onPluginCall.set(this, (id, serviceName, method, args, meta) => {
|
|
65
65
|
this.onPluginCall?.(id, serviceName, method, args, meta);
|
|
66
66
|
if (serviceName === RealtimeDefinition.fullName &&
|
|
67
67
|
method === RealtimeDefinition.methods.send.name)
|
|
@@ -70,8 +70,8 @@ export class AppUILooper {
|
|
|
70
70
|
}
|
|
71
71
|
/** Get the current app state with the current post state. */
|
|
72
72
|
get appState() {
|
|
73
|
-
__classPrivateFieldGet(this,
|
|
74
|
-
return __classPrivateFieldGet(this,
|
|
73
|
+
__classPrivateFieldGet(this, _Dispatcher_appState, "f").__postData = { thingId: this.postID, config: this.postConfig };
|
|
74
|
+
return __classPrivateFieldGet(this, _Dispatcher_appState, "f");
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Load an app bundle into the local runtime, if available. The bundle is
|
|
@@ -79,42 +79,42 @@ export class AppUILooper {
|
|
|
79
79
|
*/
|
|
80
80
|
async load(app, sandbox) {
|
|
81
81
|
this.unload();
|
|
82
|
-
__classPrivateFieldSet(this,
|
|
82
|
+
__classPrivateFieldSet(this, _Dispatcher_app, app, "f");
|
|
83
83
|
try {
|
|
84
84
|
await this._local?.loadBundle(app, sandbox);
|
|
85
85
|
}
|
|
86
86
|
catch (err) {
|
|
87
|
-
__classPrivateFieldGet(this,
|
|
87
|
+
__classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_onError).call(this, app, 'Error', err);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
queueEvent(ev) {
|
|
91
|
-
const app = __classPrivateFieldGet(this,
|
|
91
|
+
const app = __classPrivateFieldGet(this, _Dispatcher_app, "f");
|
|
92
92
|
if (ev.async) {
|
|
93
93
|
// TODO: Add QoS for different types of events on alternate queues. For
|
|
94
94
|
// now, treat alternate queues as having infinite concurrency.
|
|
95
|
-
void __classPrivateFieldGet(this,
|
|
95
|
+
void __classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_processEvent).call(this, app, ev);
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
98
|
-
void __classPrivateFieldGet(this,
|
|
98
|
+
void __classPrivateFieldGet(this, _Dispatcher_q, "f").add(() => __classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_processEvent).call(this, app, ev));
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
queueRenderPost(type, id, data) {
|
|
102
|
-
const app = __classPrivateFieldGet(this,
|
|
103
|
-
void __classPrivateFieldGet(this,
|
|
102
|
+
const app = __classPrivateFieldGet(this, _Dispatcher_app, "f");
|
|
103
|
+
void __classPrivateFieldGet(this, _Dispatcher_q, "f").add(() => __classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_renderPost).call(this, app, type, id, data));
|
|
104
104
|
}
|
|
105
105
|
get rendered() {
|
|
106
|
-
return __classPrivateFieldGet(this,
|
|
106
|
+
return __classPrivateFieldGet(this, _Dispatcher_rendered, "f");
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Discard app and render state. This is used indirectly by devvit-preview
|
|
110
110
|
* which frequently loads new bundles.
|
|
111
111
|
*/
|
|
112
112
|
resetAppState() {
|
|
113
|
-
__classPrivateFieldSet(this,
|
|
114
|
-
__classPrivateFieldSet(this,
|
|
113
|
+
__classPrivateFieldSet(this, _Dispatcher_rendered, false, "f");
|
|
114
|
+
__classPrivateFieldSet(this, _Dispatcher_appState, {}, "f");
|
|
115
115
|
}
|
|
116
116
|
set runtimeDebugLogging(on) {
|
|
117
|
-
__classPrivateFieldSet(this,
|
|
117
|
+
__classPrivateFieldSet(this, _Dispatcher_runtimeDebugLogging, on, "f");
|
|
118
118
|
if (this._local)
|
|
119
119
|
this._local.runtimeDebugLogging = on;
|
|
120
120
|
}
|
|
@@ -123,28 +123,28 @@ export class AppUILooper {
|
|
|
123
123
|
this.unload();
|
|
124
124
|
this._local = src
|
|
125
125
|
? new BrowserLiteClient(src, (type, err) => this.onError?.(type, err), {
|
|
126
|
-
callback: __classPrivateFieldGet(this,
|
|
126
|
+
callback: __classPrivateFieldGet(this, _Dispatcher_onPluginCall, "f"),
|
|
127
127
|
plugins: [],
|
|
128
128
|
})
|
|
129
129
|
: undefined;
|
|
130
130
|
if (this._local)
|
|
131
|
-
this._local.runtimeDebugLogging = __classPrivateFieldGet(this,
|
|
131
|
+
this._local.runtimeDebugLogging = __classPrivateFieldGet(this, _Dispatcher_runtimeDebugLogging, "f");
|
|
132
132
|
}
|
|
133
133
|
/** Unload the app and reject any open requests. */
|
|
134
134
|
unload() {
|
|
135
|
-
__classPrivateFieldSet(this,
|
|
136
|
-
if (__classPrivateFieldGet(this,
|
|
137
|
-
clearTimeout(__classPrivateFieldGet(this,
|
|
138
|
-
__classPrivateFieldGet(this,
|
|
135
|
+
__classPrivateFieldSet(this, _Dispatcher_app, undefined, "f");
|
|
136
|
+
if (__classPrivateFieldGet(this, _Dispatcher_rerenderTimeout, "f") != null)
|
|
137
|
+
clearTimeout(__classPrivateFieldGet(this, _Dispatcher_rerenderTimeout, "f"));
|
|
138
|
+
__classPrivateFieldGet(this, _Dispatcher_q, "f").clear();
|
|
139
139
|
this._local?.quit();
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
_Dispatcher_app = new WeakMap(), _Dispatcher_appState = new WeakMap(), _Dispatcher_q = new WeakMap(), _Dispatcher_rendered = new WeakMap(), _Dispatcher_rerenderTimeout = new WeakMap(), _Dispatcher_runtimeDebugLogging = new WeakMap(), _Dispatcher_onPluginCall = new WeakMap(), _Dispatcher_instances = new WeakSet(), _Dispatcher_onEffects = function _Dispatcher_onEffects(renderType, effects) {
|
|
143
143
|
for (const effect of effects) {
|
|
144
144
|
if (effect.rerenderUi) {
|
|
145
|
-
if (__classPrivateFieldGet(this,
|
|
146
|
-
clearTimeout(__classPrivateFieldGet(this,
|
|
147
|
-
__classPrivateFieldSet(this,
|
|
145
|
+
if (__classPrivateFieldGet(this, _Dispatcher_rerenderTimeout, "f") != null)
|
|
146
|
+
clearTimeout(__classPrivateFieldGet(this, _Dispatcher_rerenderTimeout, "f"));
|
|
147
|
+
__classPrivateFieldSet(this, _Dispatcher_rerenderTimeout, setTimeout(() => {
|
|
148
148
|
this.queueRenderPost(BlockRenderEventType.RENDER_EFFECT_EVENT, 'rerender-effect', {});
|
|
149
149
|
}, (effect.rerenderUi.delaySeconds ?? 0) * 1000), "f");
|
|
150
150
|
}
|
|
@@ -156,16 +156,16 @@ _AppUILooper_app = new WeakMap(), _AppUILooper_appState = new WeakMap(), _AppUIL
|
|
|
156
156
|
this.onUserAction?.(effect);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
},
|
|
159
|
+
}, _Dispatcher_onError = function _Dispatcher_onError(app, type, err) {
|
|
160
160
|
// Test if error was for a previously loaded bundle. If so, it's a hanging
|
|
161
161
|
// request waiting for the BrowserLiteClient.quit() rejection. We can clear
|
|
162
162
|
// enqueued requests on quit() but not in-flight requests. If app is
|
|
163
163
|
// undefined, no assumptions can be made about the request since it was for
|
|
164
164
|
// remote execution
|
|
165
|
-
if (app && __classPrivateFieldGet(this,
|
|
165
|
+
if (app && __classPrivateFieldGet(this, _Dispatcher_app, "f") !== app)
|
|
166
166
|
return;
|
|
167
167
|
this.onError?.(type, err);
|
|
168
|
-
},
|
|
168
|
+
}, _Dispatcher_processEvent = async function _Dispatcher_processEvent(app, ev) {
|
|
169
169
|
let rsp;
|
|
170
170
|
const req = { event: ev, state: this.appState };
|
|
171
171
|
if (this._local?.ready && !ev.remoteOnly) {
|
|
@@ -174,7 +174,7 @@ _AppUILooper_app = new WeakMap(), _AppUILooper_appState = new WeakMap(), _AppUIL
|
|
|
174
174
|
}
|
|
175
175
|
catch (err) {
|
|
176
176
|
if (!isCircuitBreaker(err) || !this.remote)
|
|
177
|
-
__classPrivateFieldGet(this,
|
|
177
|
+
__classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_onError).call(this, app, 'Error', err);
|
|
178
178
|
if (devvit?.logLocalErrors)
|
|
179
179
|
console.info('remote call', err);
|
|
180
180
|
}
|
|
@@ -184,20 +184,20 @@ _AppUILooper_app = new WeakMap(), _AppUILooper_appState = new WeakMap(), _AppUIL
|
|
|
184
184
|
rsp = await this.remote?.HandleUIEvent(req, this.meta);
|
|
185
185
|
}
|
|
186
186
|
catch (err) {
|
|
187
|
-
__classPrivateFieldGet(this,
|
|
187
|
+
__classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_onError).call(this, app, 'Error', err);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
if (rsp) {
|
|
191
191
|
// Can only change state on the main queue.
|
|
192
192
|
if (!ev.async) {
|
|
193
|
-
__classPrivateFieldSet(this,
|
|
193
|
+
__classPrivateFieldSet(this, _Dispatcher_appState, rsp.state ?? {}, "f");
|
|
194
194
|
}
|
|
195
195
|
const renderType = ev.realtimeEvent
|
|
196
196
|
? BlockRenderEventType.RENDER_EFFECT_EVENT
|
|
197
197
|
: BlockRenderEventType.RENDER_USER_ACTION;
|
|
198
|
-
__classPrivateFieldGet(this,
|
|
198
|
+
__classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_onEffects).call(this, renderType, rsp.effects);
|
|
199
199
|
}
|
|
200
|
-
},
|
|
200
|
+
}, _Dispatcher_renderPost = async function _Dispatcher_renderPost(app, type, id, data) {
|
|
201
201
|
const req = {
|
|
202
202
|
blocks: { type, id, data },
|
|
203
203
|
state: this.appState,
|
|
@@ -212,7 +212,7 @@ _AppUILooper_app = new WeakMap(), _AppUILooper_appState = new WeakMap(), _AppUIL
|
|
|
212
212
|
if (isCircuitBreaker(err) && err.response)
|
|
213
213
|
rsp = err.response;
|
|
214
214
|
if (!isCircuitBreaker(err) || !this.remote)
|
|
215
|
-
__classPrivateFieldGet(this,
|
|
215
|
+
__classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_onError).call(this, app, 'Error', err);
|
|
216
216
|
if (devvit?.logLocalErrors)
|
|
217
217
|
console.info('remote call', err);
|
|
218
218
|
}
|
|
@@ -222,14 +222,14 @@ _AppUILooper_app = new WeakMap(), _AppUILooper_appState = new WeakMap(), _AppUIL
|
|
|
222
222
|
rsp = await this.remote?.RenderPost(req, this.meta);
|
|
223
223
|
}
|
|
224
224
|
catch (err) {
|
|
225
|
-
__classPrivateFieldGet(this,
|
|
225
|
+
__classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_onError).call(this, app, 'Error', err);
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
if (rsp) {
|
|
229
|
-
__classPrivateFieldSet(this,
|
|
229
|
+
__classPrivateFieldSet(this, _Dispatcher_rendered, true, "f");
|
|
230
230
|
if (rsp.state)
|
|
231
|
-
__classPrivateFieldSet(this,
|
|
231
|
+
__classPrivateFieldSet(this, _Dispatcher_appState, rsp.state, "f");
|
|
232
232
|
this.onRenderPost?.(req, rsp);
|
|
233
|
-
__classPrivateFieldGet(this,
|
|
233
|
+
__classPrivateFieldGet(this, _Dispatcher_instances, "m", _Dispatcher_onEffects).call(this, req.blocks.type, rsp.effects);
|
|
234
234
|
}
|
|
235
235
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.test.d.ts","sourceRoot":"","sources":["../../library/src/client/dispatcher.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/ui-renderer",
|
|
3
|
-
"version": "0.10.19-next-2024-04-
|
|
3
|
+
"version": "0.10.19-next-2024-04-18-58e48dd7c.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
},
|
|
56
56
|
"types": "./index.d.ts",
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@devvit/protos": "0.10.19-next-2024-04-
|
|
59
|
-
"@devvit/runtime-lite": "0.10.19-next-2024-04-
|
|
60
|
-
"@devvit/runtimes": "0.10.19-next-2024-04-
|
|
61
|
-
"@devvit/shared-types": "0.10.19-next-2024-04-
|
|
58
|
+
"@devvit/protos": "0.10.19-next-2024-04-18-58e48dd7c.0",
|
|
59
|
+
"@devvit/runtime-lite": "0.10.19-next-2024-04-18-58e48dd7c.0",
|
|
60
|
+
"@devvit/runtimes": "0.10.19-next-2024-04-18-58e48dd7c.0",
|
|
61
|
+
"@devvit/shared-types": "0.10.19-next-2024-04-18-58e48dd7c.0",
|
|
62
62
|
"@dotlottie/player-component": "2.7.2",
|
|
63
63
|
"p-queue": "7.3.4",
|
|
64
64
|
"rxjs": "7.8.1"
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@devvit/eslint-config": "0.10.18",
|
|
87
|
-
"@devvit/public-api": "0.10.19-next-2024-04-
|
|
87
|
+
"@devvit/public-api": "0.10.19-next-2024-04-18-58e48dd7c.0",
|
|
88
88
|
"@devvit/repo-tools": "0.10.18",
|
|
89
|
-
"@devvit/tsconfig": "0.10.19-next-2024-04-
|
|
89
|
+
"@devvit/tsconfig": "0.10.19-next-2024-04-18-58e48dd7c.0",
|
|
90
90
|
"@lit-labs/ssr": "^2.2.3",
|
|
91
91
|
"@lit/localize": "0.11.4",
|
|
92
92
|
"@open-wc/testing-helpers": "2.3.0",
|
|
@@ -119,5 +119,5 @@
|
|
|
119
119
|
"directory": "dist"
|
|
120
120
|
},
|
|
121
121
|
"source": "./src/index.ts",
|
|
122
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "fd077aa5226d7bbcabada2877c3346ae8fe23a15"
|
|
123
123
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-ui-looper.d.ts","sourceRoot":"","sources":["../../library/src/client/app-ui-looper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,MAAM,EAGN,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,EACN,OAAO,EACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAsB,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EAEX,MAAM,kDAAkD,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAGlF,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAG7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAQzC,KAAK,QAAQ,GAAG;IACd,UAAU,CAAC,EAAE;QACX,OAAO,EAAE,GAAG,GAAG,SAAS,CAAC;QACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;KACtC,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AACF,KAAK,SAAS,GAAG;IAA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