-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.txt
More file actions
51 lines (41 loc) · 2.84 KB
/
notes.txt
File metadata and controls
51 lines (41 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
- Module Pattern
- Utilizes 'immediatily-invoked function expressions'
- Provides privacy
- Heavily used in Yahoos YUI library
- Mediator Pattern
- A real-world analogy could be a typical airport traffic control system.
A tower (Mediator) handles what planes can take off and land because all communications (notifications being listened out for or broadcast) are done from the planes to the control tower, rather than from plane-to-plane.
A centralized controller is key to the success of this system and that's really the role a Mediator plays in software design.
- Iterator Pattern
- ( nodejsdp.link/tree-traversal )
- In JavaScript, however, iterators work great even with other types of constructs, which are not necessarily containers, such as event emitters and streams.
Therefore, we can say in more general terms that the Iterator pattern defines an interface to iterate over elements produced or retrieved in sequence
- The @@name convention indicates a well-known symbol according to the ES6 specification. To find out more, you can check out the relative section of the ES6 specification at nodejsdp.link/es6-well-known-symbols.
The following are some JavaScript built-in APIs accepting iterables:
• Map([iterable]) : nodejsdp.link/map-constructor
• WeakMap([iterable]) : nodejsdp.link/weakmap-constructor
• Set([iterable]) : nodejsdp.link/set-constructor
• WeakSet([iterable]) : nodejsdp.link/weakset-constructor
• Promise.all(iterable) : nodejsdp.link/promise-all
• Promise.race(iterable) : nodejsdp.link/promise-race
• Array.from(iterable) : nodejsdp.link/array-from
On the Node.js side, one notable API accepting an iterable is stream.Readable.from(iterable, [options]) ( nodejsdp.link/readable-from ),
which creates a readable stream out of an iterable object.
-Generator Pattern
- To define a generator function, we need to use the function* declaration (the function keyword followed by an asterisk):
function * myGenerator () {
// generator body
// yield "asdf" // return this value then pause
// yield "asdf" // return this value then pause
// yield "asdf" // return this value then pause
// return "asdf" // return this value then function stopped
}
- Invoking a generator function will not execute its body immediately.
Rather, it will return a generator object, which, as we already mentioned, is both an iterator and an iterable.
- Two other extra features:
throw() :
return() : forces to terminate generator
- Middleware Pattern
- Express: A wellkown Middleware pattern
- If you want to know more about the Intercepting Filter pattern, the following article is a good starting point:
nodejsdp.link/intercepting-filter. Similarly, a nice overview of the Chain of Responsibility pattern is available