Skip to content

Commit 330d041

Browse files
committed
Make crow-tech module from Chapter 11 loadable in Node
Issue marijnh#344
1 parent 7c7eec6 commit 330d041

File tree

2 files changed

+8
-39
lines changed

2 files changed

+8
-39
lines changed

11_async.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{meta {load_files: ["code/crows.js", "code/chapter/11_async.js"]}}}
1+
{{meta {load_files: ["code/crow-tech.js", "code/chapter/11_async.js"]}}}
22

33
# Asynchronous Programming
44

@@ -185,7 +185,7 @@ nest, a crow could run code like this:
185185
{{index "readStorage function"}}
186186

187187
```{includeCode: "top_lines: 1"}
188-
import {bigOak} from "crow-tech";
188+
import {bigOak} from "./crow-tech";
189189
190190
bigOak.readStorage("food caches", caches => {
191191
let firstCache = caches[0];
@@ -216,7 +216,7 @@ response.
216216

217217
{{index "crow-tech module", "send method"}}
218218

219-
The interface exported by the `"crow-tech"` module provides
219+
The interface exported by the `"./crow-tech"` module provides
220220
callback-based functions for communication. Nests have a `send` method
221221
that sends off a request. It expects the name of the target nest, the
222222
type of the request, and the content of the request as its first three
@@ -237,7 +237,7 @@ our handler code on all connected nests.
237237
{{index "defineRequestType function"}}
238238

239239
```{includeCode: true}
240-
import {defineRequestType} from "crow-tech";
240+
import {defineRequestType} from "./crow-tech";
241241
242242
defineRequestType("note", (nest, content, source, done) => {
243243
console.log(`${nest.name} received note: ${content}`);
@@ -625,7 +625,7 @@ whole network has received the message.
625625
{{index "sendGossip function"}}
626626

627627
```{includeCode: true}
628-
import {everywhere} from "crow-tech";
628+
import {everywhere} from "./crow-tech";
629629
630630
everywhere(nest => {
631631
nest.state.gossip = [];

code/crows.js renamed to code/crow-tech.js

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -127,41 +127,10 @@
127127

128128
if (typeof window != "undefined") {
129129
window.require = name => {
130-
if (name != "crow-tech") throw new Error("Crow nests can only require \"crow-tech\"")
130+
if (name != "./crow-tech") throw new Error("Crow nests can only require \"./crow-tech\"")
131131
return exports
132132
}
133-
134-
window.List = class List {
135-
constructor(value, rest) {
136-
this.value = value;
137-
this.rest = rest;
138-
}
139-
140-
toArray() {
141-
let array = [];
142-
for (let list = this; list != List.empty; list = list.rest) {
143-
array.push(list.value);
144-
}
145-
return array;
146-
}
147-
148-
get length() {
149-
let length = 0;
150-
for (let list = this; list != List.empty; list = list.rest) {
151-
length++;
152-
}
153-
return length;
154-
}
155-
156-
static fromArray(array) {
157-
let list = List.empty;
158-
for (let i = array.length - 1; i >= 0; i--) {
159-
list = new List(array[i], list);
160-
}
161-
return list;
162-
}
163-
}
164-
165-
List.empty = new List(undefined, undefined);
133+
} else if (typeof module != "undefined" && module.exports) {
134+
module.exports = exports
166135
}
167136
})()

0 commit comments

Comments
 (0)