summaryrefslogtreecommitdiff
path: root/docs/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'docs/runtime')
-rw-r--r--docs/runtime/program_lifecycle.md12
-rw-r--r--docs/runtime/stability.md21
-rw-r--r--docs/runtime/workers.md29
3 files changed, 48 insertions, 14 deletions
diff --git a/docs/runtime/program_lifecycle.md b/docs/runtime/program_lifecycle.md
index 4a94d6724..7f6035048 100644
--- a/docs/runtime/program_lifecycle.md
+++ b/docs/runtime/program_lifecycle.md
@@ -8,8 +8,9 @@ for `unload` events need to be synchronous. Both events cannot be cancelled.
Example:
+**main.ts**
+
```ts
-// main.ts
import "./imported.ts";
const handler = (e: Event): void => {
@@ -29,8 +30,11 @@ window.onunload = (e: Event): void => {
};
console.log("log from main script");
+```
+
+**imported.ts**
-// imported.ts
+```ts
const handler = (e: Event): void => {
console.log(`got ${e.type} event in event handler (imported)`);
};
@@ -68,3 +72,7 @@ got unload event in event handler (main)
All listeners added using `window.addEventListener` were run, but
`window.onload` and `window.onunload` defined in `main.ts` overrode handlers
defined in `imported.ts`.
+
+In other words, you can register multiple `window.addEventListener` `"load"` or
+`"unload"` events, but only the last loaded `window.onload` or `window.onunload`
+events will be executed.
diff --git a/docs/runtime/stability.md b/docs/runtime/stability.md
index 7fcc0f0b0..298a788d4 100644
--- a/docs/runtime/stability.md
+++ b/docs/runtime/stability.md
@@ -5,17 +5,28 @@ strive to make code working under 1.0.0 continue to work in future versions.
However, not all of Deno's features are ready for production yet. Features which
are not ready, because they are still in draft phase, are locked behind the
-`--unstable` command line flag. Passing this flag does a few things:
+`--unstable` command line flag.
+
+```shell
+deno run --unstable mod_which_uses_unstable_stuff.ts
+```
+
+Passing this flag does a few things:
- It enables the use of unstable APIs during runtime.
- It adds the
- [`lib.deno.unstable.d.ts`](https://github.com/denoland/deno/blob/master/cli/js/lib.deno.unstable.d.ts)
+ [`lib.deno.unstable.d.ts`](https://doc.deno.land/https/raw.githubusercontent.com/denoland/deno/master/cli/js/lib.deno.unstable.d.ts)
file to the list of TypeScript definitions that are used for type checking.
This includes the output of `deno types`.
-You should be aware that unstable APIs have probably **not undergone a security
+You should be aware that many unstable APIs have **not undergone a security
review**, are likely to have **breaking API changes** in the future, and are
**not ready for production**.
-Furthermore Deno's standard modules (https://deno.land/std/) are not yet stable.
-We version the standard modules differently from the CLI to reflect this.
+### Standard modules
+
+Deno's standard modules (https://deno.land/std/) are not yet stable. We
+currently version the standard modules differently from the CLI to reflect this.
+Note that unlike the `Deno` namespace, the use of the standard modules do not
+require the `--unstable` flag (unless the standard module itself makes use of an
+unstable Deno feature).
diff --git a/docs/runtime/workers.md b/docs/runtime/workers.md
index 89541cee7..110255b8b 100644
--- a/docs/runtime/workers.md
+++ b/docs/runtime/workers.md
@@ -25,11 +25,15 @@ requires appropriate permission for this action.
For workers using local modules; `--allow-read` permission is required:
+**main.ts**
+
```ts
-// main.ts
new Worker("./worker.ts", { type: "module" });
+```
-// worker.ts
+**worker.ts**
+
+```ts
console.log("hello world");
self.close();
```
@@ -44,11 +48,15 @@ hello world
For workers using remote modules; `--allow-net` permission is required:
+**main.ts**
+
```ts
-// main.ts
new Worker("https://example.com/worker.ts", { type: "module" });
+```
-// worker.ts
+**worker.ts** (at https[]()://example.com/worker.ts)
+
+```ts
console.log("hello world");
self.close();
```
@@ -70,20 +78,27 @@ By default the `Deno` namespace is not available in worker scope.
To add the `Deno` namespace pass `deno: true` option when creating new worker:
+**main.js**
+
```ts
-// main.js
const worker = new Worker("./worker.js", { type: "module", deno: true });
worker.postMessage({ filename: "./log.txt" });
+```
-// worker.js
+**worker.js**
+
+```ts
self.onmessage = async (e) => {
const { filename } = e.data;
const text = await Deno.readTextFile(filename);
console.log(text);
self.close();
};
+```
+
+**log.txt**
-// log.txt
+```
hello world
```