|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "This lesson is about JavaScript asynchronous (async) code and [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).\n", |
| 8 | + "\n", |
| 9 | + "Asynchronous code is code that executes outside of the main thread, or \"in the background\". This is in direct contrast to most code, synchronous code, that executes one line at a time.\n", |
| 10 | + "\n", |
| 11 | + "A good example of asynchronous code is event handlers.\n", |
| 12 | + "\n", |
| 13 | + "*(Note: The code below doesn't work in the notebook)*" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "code", |
| 18 | + "execution_count": 11, |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [ |
| 21 | + { |
| 22 | + "name": "stdout", |
| 23 | + "output_type": "stream", |
| 24 | + "text": [ |
| 25 | + "making button\n" |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "data": { |
| 30 | + "text/html": [ |
| 31 | + "<button id=\"button\" onclick=\"handleClick()\">Click me</button>" |
| 32 | + ] |
| 33 | + }, |
| 34 | + "execution_count": 11, |
| 35 | + "metadata": {}, |
| 36 | + "output_type": "execute_result" |
| 37 | + } |
| 38 | + ], |
| 39 | + "source": [ |
| 40 | + "const { html } = Deno.jupyter;\n", |
| 41 | + "\n", |
| 42 | + "function handleClick() {\n", |
| 43 | + " console.log(\"Button clicked!\");\n", |
| 44 | + " document.getElementById(\"button\").textContent = \"Clicked!\";\n", |
| 45 | + "}\n", |
| 46 | + "\n", |
| 47 | + "html`<button id=\"button\" onclick=\"handleClick()\">Click me</button>`;" |
| 48 | + ] |
| 49 | + } |
| 50 | + ], |
| 51 | + "metadata": { |
| 52 | + "kernelspec": { |
| 53 | + "display_name": "Deno", |
| 54 | + "language": "typescript", |
| 55 | + "name": "deno" |
| 56 | + }, |
| 57 | + "language_info": { |
| 58 | + "codemirror_mode": "typescript", |
| 59 | + "file_extension": ".ts", |
| 60 | + "mimetype": "text/x.typescript", |
| 61 | + "name": "typescript", |
| 62 | + "nbconvert_exporter": "script", |
| 63 | + "pygments_lexer": "typescript", |
| 64 | + "version": "5.5.2" |
| 65 | + } |
| 66 | + }, |
| 67 | + "nbformat": 4, |
| 68 | + "nbformat_minor": 2 |
| 69 | +} |
0 commit comments