You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/blog/directives-and-the-platform-boundary.md
+60-2Lines changed: 60 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -192,6 +192,64 @@ Even durable tasks, caching strategies, and execution locations are now being en
192
192
193
193
---
194
194
195
+
### Considering APIs instead of directives for option‑rich features
196
+
197
+
Durable execution is a good example (e.g., `'use workflow'`, `'use step'`), but the point is general: directives can collapse behavior to a boolean, while many features benefit from options and room to evolve. Compilers and transforms can support either surface; this is about choosing the right one for longevity and clarity.
198
+
199
+
```js
200
+
'use workflow'
201
+
'use step'
202
+
```
203
+
204
+
One option: an explicit API with provenance and options:
Function forms can be just as AST/transform‑friendly as directives, and they carry provenance (imports) and type‑safety.
226
+
227
+
Another option is to inject a global once and type it:
228
+
229
+
```ts
230
+
// bootstrap once
231
+
globalThis.workflow=createWorkflow()
232
+
// global types (e.g., global.d.ts)
233
+
declareglobal {
234
+
var workflow:typeofimport('@workflows/workflow').workflow
235
+
}
236
+
```
237
+
238
+
Usage stays API‑shaped, without directives:
239
+
240
+
```ts
241
+
exportconst task =workflow(
242
+
async () => {
243
+
/* ... */
244
+
},
245
+
{ retries: 5 }
246
+
)
247
+
```
248
+
249
+
Compilers that extend ergonomics are great. Just look at JSX is a useful precedent! We just need to do it carefully and responsibly: extend via APIs with clear provenance and types, not top‑level strings that look like the language. These are options, not prescriptions.
250
+
251
+
---
252
+
195
253
### Subtle forms of lock‑in can emerge
196
254
197
255
Even when there is no bad intent, directives create lock in by design:
@@ -222,7 +280,7 @@ If multiple frameworks truly want shared primitives, a responsible path is:
222
280
- Propose primitives to TC39 when appropriate
223
281
- Keep non standard features clearly scoped to API space, not language space
224
282
225
-
Directives should be rare, stable, and standardized—used judiciously rather than proliferating across vendors.
283
+
Directives should be rare, stable, standardized and especially used judiciously rather than proliferating across vendors.
226
284
227
285
---
228
286
@@ -234,7 +292,7 @@ It’s tempting to compare criticism of directives to the early skepticism aroun
234
292
235
293
### The bottom line
236
294
237
-
Framework directives might feel like DX magic today, but the current trend risks a more fragmented future—dialects defined not by standards, but by tools.
295
+
Framework directives might feel like DX magic today, but the current trend risks a more fragmented future consisting of dialects defined not by standards, but by tools.
0 commit comments