HTML and CSS Reference
In-Depth Information
quickly as errors will be easy to track down when we run tests every time we add a
handful of lines of code.
The library needs to define the role of the observer as well as the observable .
However, in contrast to the Java solution mentioned earlier, JavaScript observers
need not be objects that conform to a certain interface. Functions are first class
objects in JavaScript, so we can simply subscribe functions directly. This means our
work consists of defining the Observable API.
11.1.2 Setting up the Environment
For this chapter we will use JsTestDriver and its default assertion framework.
Refer to Chapter 3, Tools of the Trade, if you have not yet set up JsTestDriver in your
development environment.
Listing 11.1 shows the initial project layout.
Listing 11.1 Directory layout for the observable project
chris@laptop:~/projects/observable $ tree
.
| -- jsTestDriver.conf
| -- lib
| `-- tdd.js
| -- src
| `-- observable.js
`-- test
`-- observable_test.js
The lib/tdd.js contains the tddjs object and the namespace method
developed in Chapter 6, Applied Functions andClosures. We will use these to develop
the observable interface namespaced inside tddjs .
The configuration file is just a plain default jsTestDriver configuration file that
runs the server on port 4224 and includes all script files, as seen in Listing 11.2.
Listing 11.2 The jsTestDriver.conf file
server: http://localhost:4224
load:
- lib/*.js
- src/*.js
- test/*.js
 
Search WWH ::




Custom Search