@devvit/public-api 0.11.0-next-2024-07-23-b981dd5cc.0 → 0.11.0-next-2024-07-24-919ab41f5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/devvit/Devvit.d.ts.map +1 -1
- package/devvit/Devvit.js +39 -49
- package/devvit/internals/blocks/handler/BlocksHandler.d.ts.map +1 -1
- package/devvit/internals/blocks/handler/BlocksHandler.js +22 -22
- package/devvit/internals/blocks/handler/RenderContext.d.ts +12 -0
- package/devvit/internals/blocks/handler/RenderContext.d.ts.map +1 -1
- package/devvit/internals/blocks/handler/RenderContext.js +3 -0
- package/devvit/internals/blocks/handler/types.d.ts +2 -2
- package/devvit/internals/blocks/handler/types.js +2 -2
- package/devvit/internals/blocks/handler/useAsync.d.ts +1 -0
- package/devvit/internals/blocks/handler/useAsync.d.ts.map +1 -1
- package/devvit/internals/blocks/handler/useState.d.ts +1 -2
- package/devvit/internals/blocks/handler/useState.d.ts.map +1 -1
- package/devvit/internals/blocks/handler/useState.js +82 -42
- package/devvit/internals/blocks/handler/useState.test.d.ts.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +1 -1
- package/meta.json +15 -151
- package/meta.min.json +17 -33
- package/package.json +7 -7
- package/public-api.d.ts +0 -2
- package/public-api.iife.js +150 -1449
- package/public-api.min.js +5 -5
- package/public-api.min.js.map +4 -4
package/devvit/Devvit.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Devvit.d.ts","sourceRoot":"","sources":["../../src/devvit/Devvit.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"Devvit.d.ts","sourceRoot":"","sources":["../../src/devvit/Devvit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAItD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO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,QAAQ,GAAG,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;QAC5C,KAAK,KAAK,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG;YAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,eAAe,CAAA;SAAE,CAAC;QAE1E,KAAK,iBAAiB,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,KAAK,GAAG,CAAC,OAAO,CAAC;KACrF;CACF"}
|
package/devvit/Devvit.js
CHANGED
@@ -9,9 +9,8 @@ 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 _a, _Devvit_appSettings, _Devvit_assets, _Devvit_config, _Devvit_customPostType, _Devvit_formDefinitions, _Devvit_installationSettings, _Devvit_menuItems, _Devvit_scheduledJobHandlers, _Devvit_triggerOnEventHandlers, _Devvit_webviewAssets, _Devvit_additionallyProvides, _Devvit_uses, _Devvit_pluginClients
|
12
|
+
var _a, _Devvit_appSettings, _Devvit_assets, _Devvit_config, _Devvit_customPostType, _Devvit_formDefinitions, _Devvit_installationSettings, _Devvit_menuItems, _Devvit_scheduledJobHandlers, _Devvit_triggerOnEventHandlers, _Devvit_webviewAssets, _Devvit_additionallyProvides, _Devvit_uses, _Devvit_pluginClients;
|
13
13
|
import * as protos from '@devvit/protos';
|
14
|
-
import { PaymentsServiceDefinition } from '@devvit/protos/payments.js';
|
15
14
|
import { Actor } from '@devvit/shared-types/Actor.js';
|
16
15
|
import { assertValidFormFields } from '../apis/ui/helpers/assertValidFormFields.js';
|
17
16
|
import { SettingScope } from '../types/index.js';
|
@@ -45,41 +44,38 @@ export class Devvit extends Actor {
|
|
45
44
|
static configure(config) {
|
46
45
|
__classPrivateFieldSet(this, _a, { ...__classPrivateFieldGet(this, _a, "f", _Devvit_config), ...config }, "f", _Devvit_config);
|
47
46
|
if (pluginIsEnabled(config.http)) {
|
48
|
-
|
47
|
+
this.use(protos.HTTPDefinition);
|
49
48
|
}
|
50
49
|
if (pluginIsEnabled(config.kvStore) || pluginIsEnabled(config.redis)) {
|
51
|
-
|
52
|
-
|
50
|
+
this.use(protos.KVStoreDefinition);
|
51
|
+
this.use(protos.RedisAPIDefinition);
|
53
52
|
}
|
54
53
|
if (pluginIsEnabled(config.media)) {
|
55
|
-
|
54
|
+
this.use(protos.MediaServiceDefinition);
|
56
55
|
}
|
57
56
|
if (pluginIsEnabled(config.modLog)) {
|
58
|
-
|
57
|
+
this.use(protos.ModlogDefinition);
|
59
58
|
}
|
60
59
|
if (pluginIsEnabled(config.redditAPI)) {
|
61
60
|
// Loading all Reddit API plugins for now.
|
62
61
|
// In the future we can split this by oauth scope or section.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
62
|
+
this.use(protos.FlairDefinition);
|
63
|
+
this.use(protos.GraphQLDefinition);
|
64
|
+
this.use(protos.LinksAndCommentsDefinition);
|
65
|
+
this.use(protos.ListingsDefinition);
|
66
|
+
this.use(protos.ModerationDefinition);
|
67
|
+
this.use(protos.ModNoteDefinition);
|
68
|
+
this.use(protos.NewModmailDefinition);
|
69
|
+
this.use(protos.PrivateMessagesDefinition);
|
70
|
+
this.use(protos.SubredditsDefinition);
|
71
|
+
this.use(protos.PostCollectionsDefinition);
|
72
|
+
this.use(protos.UsersDefinition);
|
73
|
+
this.use(protos.WidgetsDefinition);
|
74
|
+
this.use(protos.WikiDefinition);
|
75
|
+
this.use(protos.RedditAPIV2Definition);
|
77
76
|
}
|
78
77
|
if (pluginIsEnabled(config.realtime)) {
|
79
|
-
|
80
|
-
}
|
81
|
-
if (pluginIsEnabled(config.payments)) {
|
82
|
-
__classPrivateFieldGet(this, _a, "m", _Devvit_use).call(this, PaymentsServiceDefinition);
|
78
|
+
this.use(protos.RealtimeDefinition);
|
83
79
|
}
|
84
80
|
}
|
85
81
|
/**
|
@@ -178,7 +174,7 @@ export class Devvit extends Actor {
|
|
178
174
|
*/
|
179
175
|
static addSchedulerJob(job) {
|
180
176
|
if (!__classPrivateFieldGet(this, _a, "f", _Devvit_pluginClients)[protos.SchedulerDefinition.fullName]) {
|
181
|
-
|
177
|
+
this.use(protos.SchedulerDefinition);
|
182
178
|
}
|
183
179
|
if (__classPrivateFieldGet(this, _a, "f", _Devvit_scheduledJobHandlers).has(job.name)) {
|
184
180
|
throw new Error(`Job ${job.name} is already defined`);
|
@@ -244,7 +240,7 @@ export class Devvit extends Actor {
|
|
244
240
|
__classPrivateFieldSet(this, _a, appSettings, "f", _Devvit_appSettings);
|
245
241
|
}
|
246
242
|
if (!__classPrivateFieldGet(this, _a, "f", _Devvit_pluginClients)[protos.SettingsDefinition.fullName]) {
|
247
|
-
|
243
|
+
this.use(protos.SettingsDefinition);
|
248
244
|
}
|
249
245
|
}
|
250
246
|
static addTrigger(triggerDefinition) {
|
@@ -278,6 +274,21 @@ export class Devvit extends Actor {
|
|
278
274
|
__classPrivateFieldGet(this, _a, "f", _Devvit_additionallyProvides).push(def);
|
279
275
|
}
|
280
276
|
/** @internal */
|
277
|
+
static use(d, opts) {
|
278
|
+
__classPrivateFieldGet(this, _a, "f", _Devvit_uses)[d.fullName] = {
|
279
|
+
def: d,
|
280
|
+
options: opts ?? {},
|
281
|
+
handler: undefined,
|
282
|
+
};
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
284
|
+
const wrapped = {};
|
285
|
+
for (const method of Object.values(d.methods)) {
|
286
|
+
wrapped[method.name] = (args, metadata) => __classPrivateFieldGet(this, _a, "f", _Devvit_uses)[d.fullName].handler?.[method.name]?.(method.requestType?.fromPartial(args ?? {}), metadata);
|
287
|
+
}
|
288
|
+
__classPrivateFieldGet(this, _a, "f", _Devvit_pluginClients)[d.fullName] = wrapped;
|
289
|
+
return wrapped;
|
290
|
+
}
|
291
|
+
/** @internal */
|
281
292
|
static get redditAPIPlugins() {
|
282
293
|
if (!pluginIsEnabled(__classPrivateFieldGet(this, _a, "f", _Devvit_config).redditAPI)) {
|
283
294
|
throw new Error('Reddit API is not enabled. You can enable it by passing `redditAPI: true` to `Devvit.configure`.');
|
@@ -364,14 +375,6 @@ export class Devvit extends Actor {
|
|
364
375
|
return realtime;
|
365
376
|
}
|
366
377
|
/** @internal */
|
367
|
-
static get paymentsPlugin() {
|
368
|
-
const payments = __classPrivateFieldGet(this, _a, "f", _Devvit_pluginClients)[PaymentsServiceDefinition.fullName];
|
369
|
-
if (!payments) {
|
370
|
-
throw new Error('Payments is not enabled. You can enable it by passing `payments: true` to `Devvit.configure`');
|
371
|
-
}
|
372
|
-
return payments;
|
373
|
-
}
|
374
|
-
/** @internal */
|
375
378
|
static get menuItems() {
|
376
379
|
return __classPrivateFieldGet(this, _a, "f", _Devvit_menuItems);
|
377
380
|
}
|
@@ -447,20 +450,7 @@ export class Devvit extends Actor {
|
|
447
450
|
}
|
448
451
|
}
|
449
452
|
}
|
450
|
-
_a = Devvit
|
451
|
-
__classPrivateFieldGet(this, _a, "f", _Devvit_uses)[d.fullName] = {
|
452
|
-
def: d,
|
453
|
-
options: opts ?? {},
|
454
|
-
handler: undefined,
|
455
|
-
};
|
456
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
457
|
-
const wrapped = {};
|
458
|
-
for (const method of Object.values(d.methods)) {
|
459
|
-
wrapped[method.name] = (args, metadata) => __classPrivateFieldGet(this, _a, "f", _Devvit_uses)[d.fullName].handler?.[method.name]?.(method.requestType?.fromPartial(args ?? {}), metadata);
|
460
|
-
}
|
461
|
-
__classPrivateFieldGet(this, _a, "f", _Devvit_pluginClients)[d.fullName] = wrapped;
|
462
|
-
return wrapped;
|
463
|
-
};
|
453
|
+
_a = Devvit;
|
464
454
|
Devvit.debug = {};
|
465
455
|
_Devvit_appSettings = { value: void 0 };
|
466
456
|
_Devvit_assets = { value: {} };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"BlocksHandler.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/BlocksHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
1
|
+
{"version":3,"file":"BlocksHandler.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/BlocksHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAK7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAgB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAe,IAAI,EAAE,UAAU,EAAE,WAAW,EAAS,MAAM,YAAY,CAAC;AAGpF;;;;;;GAMG;AACH,eAAO,IAAI,oBAAoB,EAAE,aAAa,GAAG,IAAW,CAAC;AAE7D,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD;AAED,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CASxD;AASD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,IAAI,EACzC,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,CAAC,GAChC,CAAC,CAkCH;AAED,eAAO,IAAI,oBAAoB,EAAE,aAAa,GAAG,IAAW,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,aAAa;;IAMxB,oBAAoB,EAAE,aAAa,GAAG,IAAI,CAAQ;gBAEtC,IAAI,EAAE,GAAG,CAAC,iBAAiB;IAMjC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAyW1E"}
|
@@ -10,7 +10,6 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
11
11
|
};
|
12
12
|
var _BlocksHandler_instances, _BlocksHandler_root, _BlocksHandler_contextBuilder, _BlocksHandler_blocksTransformer, _BlocksHandler_debug_get, _BlocksHandler_loadHooks, _BlocksHandler_handleAsyncQueues, _BlocksHandler_attemptHook, _BlocksHandler_handleMainQueue, _BlocksHandler_renderRoot, _BlocksHandler_render, _BlocksHandler_renderList, _BlocksHandler_renderElement, _BlocksHandler_reifyProps;
|
13
|
-
import isEqual from 'lodash.isequal';
|
14
13
|
import { BlocksTransformer } from '../BlocksTransformer.js';
|
15
14
|
import { ContextBuilder } from './ContextBuilder.js';
|
16
15
|
import { _isTombstone, RenderContext } from './RenderContext.js';
|
@@ -69,6 +68,7 @@ export function registerHook(options, initializer) {
|
|
69
68
|
assertValidNamespace(options.namespace);
|
70
69
|
const hookId = _activeRenderContext.nextHookId(options);
|
71
70
|
const context = _activeRenderContext;
|
71
|
+
context._touched[hookId] = true;
|
72
72
|
const params = {
|
73
73
|
hookId,
|
74
74
|
invalidate: () => {
|
@@ -129,6 +129,13 @@ export class BlocksHandler {
|
|
129
129
|
let changed;
|
130
130
|
let progress;
|
131
131
|
let remaining = [...eventsToProcess];
|
132
|
+
/**
|
133
|
+
* When purely rendering, we now add one synthetic event. This enables us to loop over the events that an initial render may generate
|
134
|
+
* in an async world. This is a bit of a hack, but it's the simplest way to handle this.
|
135
|
+
*/
|
136
|
+
if (eventsToProcess.length === 0) {
|
137
|
+
eventsToProcess.push({});
|
138
|
+
}
|
132
139
|
if (__classPrivateFieldGet(this, _BlocksHandler_instances, "a", _BlocksHandler_debug_get))
|
133
140
|
console.debug('[blocks] starting processing events');
|
134
141
|
while (eventsToProcess.length > 0) {
|
@@ -163,6 +170,7 @@ export class BlocksHandler {
|
|
163
170
|
catch (e) {
|
164
171
|
if (__classPrivateFieldGet(this, _BlocksHandler_instances, "a", _BlocksHandler_debug_get))
|
165
172
|
console.debug('[blocks] caught in handler', e);
|
173
|
+
context._latestRenderContent = undefined;
|
166
174
|
/**
|
167
175
|
* If we have a progress, we can recover from an error by rolling back to the last progress, and then letting the
|
168
176
|
* remaining events be reprocessed.
|
@@ -180,6 +188,7 @@ export class BlocksHandler {
|
|
180
188
|
break;
|
181
189
|
}
|
182
190
|
else {
|
191
|
+
console.error('[blocks] unhandled error in handler', e);
|
183
192
|
throw e;
|
184
193
|
}
|
185
194
|
}
|
@@ -220,27 +229,12 @@ export class BlocksHandler {
|
|
220
229
|
remaining = [...eventsToProcess];
|
221
230
|
}
|
222
231
|
} // End of while loop
|
232
|
+
// Rendering only happens on the main queue.
|
223
233
|
if (isMainQueue) {
|
224
|
-
|
225
|
-
|
226
|
-
const effectsCopy = { ...context._effects };
|
227
|
-
// Rendering only happens on the main queue.
|
228
|
-
const tags = __classPrivateFieldGet(this, _BlocksHandler_instances, "m", _BlocksHandler_renderRoot).call(this, __classPrivateFieldGet(this, _BlocksHandler_root, "f"), context._rootProps ?? {}, context);
|
229
|
-
/**
|
230
|
-
* It's technically ok for renderRoot to mutate, but that's only in the context of loadHooks. This render should
|
231
|
-
* be idempotent, so we're going to enforce that it doesn't mutate state.
|
232
|
-
*
|
233
|
-
* TODO: hide this behind a flag, because it's possibly expensive.
|
234
|
-
*/
|
235
|
-
if (!isEqual(context._state, stateCopy)) {
|
236
|
-
console.error('[blocks] State was mutated during rendering', context._state, stateCopy);
|
237
|
-
}
|
238
|
-
if (!isEqual(context._requeueEvents, eventsCopy)) {
|
239
|
-
console.error('[blocks] Events were mutated during rendering', context._requeueEvents, eventsCopy);
|
240
|
-
}
|
241
|
-
if (!isEqual(context._effects, effectsCopy)) {
|
242
|
-
console.error('[blocks] Effects were mutated during rendering', context._effects, effectsCopy);
|
234
|
+
if (!context._latestRenderContent) {
|
235
|
+
context._latestRenderContent = __classPrivateFieldGet(this, _BlocksHandler_instances, "m", _BlocksHandler_renderRoot).call(this, __classPrivateFieldGet(this, _BlocksHandler_root, "f"), context.request.props ?? {}, context);
|
243
236
|
}
|
237
|
+
const tags = context._latestRenderContent;
|
244
238
|
if (tags) {
|
245
239
|
blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").createBlocksElementOrThrow(tags);
|
246
240
|
blocks = __classPrivateFieldGet(this, _BlocksHandler_blocksTransformer, "f").ensureRootBlock(blocks);
|
@@ -258,8 +252,13 @@ _BlocksHandler_root = new WeakMap(), _BlocksHandler_contextBuilder = new WeakMap
|
|
258
252
|
return !!this._latestRenderContext?.devvitContext.debug.blocks;
|
259
253
|
}, _BlocksHandler_loadHooks = function _BlocksHandler_loadHooks(context, ..._events) {
|
260
254
|
// TBD: partial rendering
|
261
|
-
context.
|
255
|
+
context._touched = {};
|
262
256
|
__classPrivateFieldGet(this, _BlocksHandler_instances, "m", _BlocksHandler_renderRoot).call(this, __classPrivateFieldGet(this, _BlocksHandler_root, "f"), context.request.props ?? {}, context);
|
257
|
+
for (const hookId in context._hooks) {
|
258
|
+
if (!context._touched[hookId]) {
|
259
|
+
delete context._hooks[hookId];
|
260
|
+
}
|
261
|
+
}
|
263
262
|
}, _BlocksHandler_handleAsyncQueues =
|
264
263
|
/**
|
265
264
|
* These can all run in parallel, because they only emit effects
|
@@ -307,7 +306,7 @@ async function _BlocksHandler_handleAsyncQueues(context, ...batch) {
|
|
307
306
|
if (__classPrivateFieldGet(this, _BlocksHandler_instances, "a", _BlocksHandler_debug_get))
|
308
307
|
console.log('[blocks] after', context._state);
|
309
308
|
}
|
310
|
-
//
|
309
|
+
// We need this to process possible unmounts given the most recent event
|
311
310
|
__classPrivateFieldGet(this, _BlocksHandler_instances, "m", _BlocksHandler_loadHooks).call(this, context);
|
312
311
|
}, _BlocksHandler_renderRoot = function _BlocksHandler_renderRoot(component, props, context) {
|
313
312
|
if (__classPrivateFieldGet(this, _BlocksHandler_instances, "a", _BlocksHandler_debug_get))
|
@@ -329,6 +328,7 @@ async function _BlocksHandler_handleAsyncQueues(context, ...batch) {
|
|
329
328
|
if (typeof root === 'string') {
|
330
329
|
throw new Error(`The root element must return a valid block, not a string. Try wrapping the element in a <text>your content</text> tag to continue.`);
|
331
330
|
}
|
331
|
+
context._latestRenderContent = root;
|
332
332
|
return root;
|
333
333
|
}
|
334
334
|
catch (e) {
|
@@ -2,6 +2,7 @@ import type { Effect, Metadata, UIEvent, UIRequest } from '@devvit/protos';
|
|
2
2
|
import type { Devvit } from '../../../Devvit.js';
|
3
3
|
import type { EffectEmitter } from '../EffectEmitter.js';
|
4
4
|
import type { BlocksState, EventHandler, Hook, HookRef, HookSegment } from './types.js';
|
5
|
+
import type { ReifiedBlockElement } from '../BlocksReconciler.js';
|
5
6
|
/**
|
6
7
|
* The RenderContext is a class that holds the state of the rendering process.
|
7
8
|
*
|
@@ -26,9 +27,20 @@ export declare class RenderContext implements EffectEmitter {
|
|
26
27
|
_effects: {
|
27
28
|
[key: string]: Effect;
|
28
29
|
};
|
30
|
+
/**
|
31
|
+
* While processing events, we do some renders to load hooks. If those renders produce valid content, then
|
32
|
+
* we won't have to render at the end of the event processing, rather we can hang onto the last render and
|
33
|
+
* reuse it.
|
34
|
+
*/
|
35
|
+
_latestRenderContent: ReifiedBlockElement | undefined;
|
36
|
+
/** Has this state been mutated since initially loaded? */
|
29
37
|
_changed: {
|
30
38
|
[hookID: string]: true;
|
31
39
|
};
|
40
|
+
/** Does this hook still exist in the most recent render? */
|
41
|
+
_touched: {
|
42
|
+
[hookID: string]: true;
|
43
|
+
};
|
32
44
|
/** Events that will re-enter the dispatcher queue */
|
33
45
|
_requeueEvents: UIEvent[];
|
34
46
|
_rootProps: {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/RenderContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
1
|
+
{"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/RenderContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAelE;;;;;;;;;GASG;AACH,qBAAa,aAAc,YAAW,aAAa;;IACjD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAElC,SAAS,EAAE,CAAC,WAAW,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAM;IACnD,MAAM,EA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AC5D,IAAI,MAAM,CAAC,KAAK,EAAE,WAAW,EAI5B;IAED,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAIhC,GAAG,IAAI,IAAI;IAIX,0BAA0B,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAInE,gCAAgC,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIzE,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI;IAG3B,4GAA4G;IAC5G,MAAM,CAAC,gCAAgC,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAI1E,sBAAsB,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAUnE,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAInD;;OAEG;IACH,kBAAkB,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI;IAmB9C,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM;CA0CzC"}
|
@@ -40,7 +40,10 @@ export class RenderContext {
|
|
40
40
|
this._hooks = {};
|
41
41
|
this._prevHookId = '';
|
42
42
|
this._effects = {};
|
43
|
+
/** Has this state been mutated since initially loaded? */
|
43
44
|
this._changed = {};
|
45
|
+
/** Does this hook still exist in the most recent render? */
|
46
|
+
this._touched = {};
|
44
47
|
/** Events that will re-enter the dispatcher queue */
|
45
48
|
this._requeueEvents = [];
|
46
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -80,8 +80,8 @@ export type HookParams = {
|
|
80
80
|
context: RenderContext;
|
81
81
|
};
|
82
82
|
/**
|
83
|
-
* Circuit-breaking triggers a {
|
84
|
-
* This triggers a {
|
83
|
+
* Circuit-breaking triggers a {scope=REMOTE, async=false, retry=true} event.
|
84
|
+
* This triggers a {scope=ALL, async=true, retry=false} event. In
|
85
85
|
* practice, that has some slight implications for how it flows through the
|
86
86
|
* event loop. If we wanted to, we could change this out, if we fully understand
|
87
87
|
* the semantics. This aligns more with useAsync than circuit-breaking today,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
|
-
* Circuit-breaking triggers a {
|
3
|
-
* This triggers a {
|
2
|
+
* Circuit-breaking triggers a {scope=REMOTE, async=false, retry=true} event.
|
3
|
+
* This triggers a {scope=ALL, async=true, retry=false} event. In
|
4
4
|
* practice, that has some slight implications for how it flows through the
|
5
5
|
* event loop. If we wanted to, we could change this out, if we fully understand
|
6
6
|
* the semantics. This aligns more with useAsync than circuit-breaking today,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useAsync.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/useAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAQ3F,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB,CAAC;
|
1
|
+
{"version":3,"file":"useAsync.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/useAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAQ3F,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAyGhF;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,EAC1C,WAAW,EAAE,wBAAwB,CAAC,CAAC,CAAC,EACxC,OAAO,GAAE,YAAiB,GACzB,cAAc,CAAC,CAAC,CAAC,CAUnB"}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { JSONValue } from '@devvit/shared-types/json.js';
|
2
|
-
import type {
|
3
|
-
export declare function useAsyncState<S extends JSONValue>(initializer: AsyncUseStateInitializer<S>): UseStateResult<S>;
|
2
|
+
import type { UseStateInitializer, UseStateResult } from '../../../../types/hooks.js';
|
4
3
|
export declare function useState(initialState: UseStateInitializer<boolean>): UseStateResult<boolean>;
|
5
4
|
export declare function useState(initialState: UseStateInitializer<number>): UseStateResult<number>;
|
6
5
|
export declare function useState(initialState: UseStateInitializer<string>): UseStateResult<string>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useState.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/useState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"useState.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/useState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAEV,mBAAmB,EACnB,cAAc,EACf,MAAM,4BAA4B,CAAC;AAoGpC,wBAAgB,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;AAC9F,wBAAgB,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;AAC5F,wBAAgB,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;AAC5F,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,EAC1C,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC,GACnC,cAAc,CAAC,CAAC,CAAC,CAAC"}
|
@@ -9,63 +9,103 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
11
|
};
|
12
|
-
var
|
12
|
+
var _UseStateHook_changed, _UseStateHook_ctx, _UseStateHook_initializer, _UseStateHook_hookId, _UseStateHook_promise;
|
13
13
|
import { registerHook } from './BlocksHandler.js';
|
14
14
|
import { RenderInterruptError } from './types.js';
|
15
|
-
|
15
|
+
/**
|
16
|
+
* Implementation of the useState hook.
|
17
|
+
*/
|
18
|
+
class UseStateHook {
|
16
19
|
constructor(initializer, params) {
|
17
|
-
this.state = { value: null,
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
__classPrivateFieldSet(this,
|
24
|
-
__classPrivateFieldSet(this,
|
25
|
-
__classPrivateFieldSet(this,
|
20
|
+
this.state = { value: null, load_state: 'initial' };
|
21
|
+
_UseStateHook_changed.set(this, void 0);
|
22
|
+
_UseStateHook_ctx.set(this, void 0);
|
23
|
+
_UseStateHook_initializer.set(this, void 0);
|
24
|
+
_UseStateHook_hookId.set(this, void 0);
|
25
|
+
_UseStateHook_promise.set(this, void 0);
|
26
|
+
__classPrivateFieldSet(this, _UseStateHook_initializer, initializer, "f");
|
27
|
+
__classPrivateFieldSet(this, _UseStateHook_hookId, params.hookId, "f");
|
28
|
+
__classPrivateFieldSet(this, _UseStateHook_changed, params.invalidate, "f");
|
29
|
+
__classPrivateFieldSet(this, _UseStateHook_ctx, params.context, "f");
|
26
30
|
}
|
31
|
+
/**
|
32
|
+
* For state initialized with a promise, this function is called when the promise resolves. This should
|
33
|
+
* happen inside the same event loop as the original call to useState, assuming circuit-breaking didn't happen.
|
34
|
+
*
|
35
|
+
* If circuit-breaking did happen, this function will be called on the server and the state will propagate to
|
36
|
+
* the client.
|
37
|
+
*
|
38
|
+
* This is intended to be synchronous in the event loop, so will block and waterfall. useAsync is the non-waterfalling
|
39
|
+
* version, but this version is provided for backwards compatibility.
|
40
|
+
*/
|
27
41
|
async onUIEvent() {
|
28
|
-
if (this.state.
|
29
|
-
|
30
|
-
|
31
|
-
|
42
|
+
if (this.state.load_state === 'loading' && __classPrivateFieldGet(this, _UseStateHook_promise, "f")) {
|
43
|
+
try {
|
44
|
+
this.state.value = await __classPrivateFieldGet(this, _UseStateHook_promise, "f");
|
45
|
+
this.state.load_state = 'loaded';
|
46
|
+
}
|
47
|
+
catch (e) {
|
48
|
+
this.state.load_state = 'error';
|
49
|
+
console.error('Error loading async state: ', e);
|
50
|
+
}
|
51
|
+
__classPrivateFieldGet(this, _UseStateHook_changed, "f").call(this);
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
/**
|
55
|
+
* This would probably be some sort of concurrent access bug. It's not clear what would put us
|
56
|
+
* in this state, but it's worth logging so we can investigate.
|
57
|
+
*/
|
58
|
+
console.warn('Invalid state: ', this.state.load_state, __classPrivateFieldGet(this, _UseStateHook_promise, "f"));
|
32
59
|
}
|
33
60
|
}
|
34
61
|
setter(action) {
|
35
62
|
this.state.value = action instanceof Function ? action(this.state.value) : action;
|
36
|
-
|
63
|
+
this.state.load_state = 'loaded';
|
64
|
+
__classPrivateFieldGet(this, _UseStateHook_changed, "f").call(this);
|
37
65
|
}
|
66
|
+
/**
|
67
|
+
* After the existing state is loaded, we need to run the initializer if there was no state found.
|
68
|
+
*/
|
38
69
|
onStateLoaded() {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
asyncRequest: { requestId: __classPrivateFieldGet(this, _AsyncStateHook_hookId, "f") },
|
44
|
-
hook: __classPrivateFieldGet(this, _AsyncStateHook_hookId, "f"),
|
45
|
-
};
|
46
|
-
__classPrivateFieldGet(this, _AsyncStateHook_ctx, "f").addToRequeueEvents(requeueEvent);
|
70
|
+
/**
|
71
|
+
* If the state is still loading, we need to throw an error to prevent using the null state.
|
72
|
+
*/
|
73
|
+
if (this.state.load_state === 'loading') {
|
47
74
|
throw new RenderInterruptError();
|
48
75
|
}
|
76
|
+
if (this.state.load_state === 'initial') {
|
77
|
+
let initialValue;
|
78
|
+
try {
|
79
|
+
initialValue =
|
80
|
+
__classPrivateFieldGet(this, _UseStateHook_initializer, "f") instanceof Function ? __classPrivateFieldGet(this, _UseStateHook_initializer, "f").call(this) : __classPrivateFieldGet(this, _UseStateHook_initializer, "f");
|
81
|
+
}
|
82
|
+
catch (e) {
|
83
|
+
console.log('error in loading async', e);
|
84
|
+
this.state.load_state = 'error';
|
85
|
+
__classPrivateFieldGet(this, _UseStateHook_changed, "f").call(this);
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
if (initialValue instanceof Promise) {
|
89
|
+
__classPrivateFieldSet(this, _UseStateHook_promise, initialValue, "f");
|
90
|
+
this.state.load_state = 'loading';
|
91
|
+
const requeueEvent = {
|
92
|
+
asyncRequest: { requestId: __classPrivateFieldGet(this, _UseStateHook_hookId, "f") },
|
93
|
+
hook: __classPrivateFieldGet(this, _UseStateHook_hookId, "f"),
|
94
|
+
};
|
95
|
+
__classPrivateFieldGet(this, _UseStateHook_ctx, "f").addToRequeueEvents(requeueEvent);
|
96
|
+
__classPrivateFieldGet(this, _UseStateHook_changed, "f").call(this);
|
97
|
+
throw new RenderInterruptError();
|
98
|
+
}
|
99
|
+
else {
|
100
|
+
this.state.value = initialValue;
|
101
|
+
this.state.load_state = 'loaded';
|
102
|
+
}
|
103
|
+
__classPrivateFieldGet(this, _UseStateHook_changed, "f").call(this);
|
104
|
+
}
|
49
105
|
}
|
50
106
|
}
|
51
|
-
|
52
|
-
export function useAsyncState(initializer) {
|
53
|
-
const hook = registerHook({ namespace: 'useAsyncState' }, (params) => {
|
54
|
-
return new AsyncStateHook(initializer, params);
|
55
|
-
});
|
56
|
-
return [hook.state.value, hook.setter.bind(hook)];
|
57
|
-
}
|
107
|
+
_UseStateHook_changed = new WeakMap(), _UseStateHook_ctx = new WeakMap(), _UseStateHook_initializer = new WeakMap(), _UseStateHook_hookId = new WeakMap(), _UseStateHook_promise = new WeakMap();
|
58
108
|
export function useState(initialState) {
|
59
|
-
const hook = registerHook({ namespace: 'useState' }, (params) =>
|
60
|
-
const state = initialState instanceof Function ? initialState() : initialState;
|
61
|
-
if (state instanceof Promise) {
|
62
|
-
return new AsyncStateHook(() => state, params);
|
63
|
-
}
|
64
|
-
const setter = (action) => {
|
65
|
-
hook.state.value = action instanceof Function ? action(hook.state.value) : action;
|
66
|
-
params.invalidate();
|
67
|
-
};
|
68
|
-
return { state: { value: state }, setter };
|
69
|
-
});
|
109
|
+
const hook = registerHook({ namespace: 'useState' }, (params) => new UseStateHook(initialState, params));
|
70
110
|
return [hook.state.value, hook.setter.bind(hook)];
|
71
111
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useState.test.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/useState.test.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"useState.test.d.ts","sourceRoot":"","sources":["../../../../../src/devvit/internals/blocks/handler/useState.test.tsx"],"names":[],"mappings":""}
|
package/index.d.ts
CHANGED
@@ -7,7 +7,7 @@ export * from './types/index.js';
|
|
7
7
|
export * from '@devvit/shared-types/json.js';
|
8
8
|
export * from './apis/ui/helpers/svg.js';
|
9
9
|
export { useAsync } from './devvit/internals/blocks/handler/useAsync.js';
|
10
|
-
export { useState
|
10
|
+
export { useState } from './devvit/internals/blocks/handler/useState.js';
|
11
11
|
export { useForm } from './devvit/internals/blocks/handler/useForm.js';
|
12
12
|
export { useInterval } from './devvit/internals/blocks/handler/useInterval.js';
|
13
13
|
export { useChannel } from './devvit/internals/blocks/handler/useChannel.js';
|
package/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,cAAc,+BAA+B,CAAC;AAC9C,YAAY,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAC;AACnF,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,cAAc,+BAA+B,CAAC;AAC9C,YAAY,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAC;AACnF,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,8CAA8C,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAC"}
|
package/index.js
CHANGED
@@ -6,7 +6,7 @@ export * from './types/index.js';
|
|
6
6
|
export * from '@devvit/shared-types/json.js';
|
7
7
|
export * from './apis/ui/helpers/svg.js';
|
8
8
|
export { useAsync } from './devvit/internals/blocks/handler/useAsync.js';
|
9
|
-
export { useState
|
9
|
+
export { useState } from './devvit/internals/blocks/handler/useState.js';
|
10
10
|
export { useForm } from './devvit/internals/blocks/handler/useForm.js';
|
11
11
|
export { useInterval } from './devvit/internals/blocks/handler/useInterval.js';
|
12
12
|
export { useChannel } from './devvit/internals/blocks/handler/useChannel.js';
|