Created Exports Files (markdown)
+17
@@ -0,0 +1,17 @@
|
||||
Alongside js files the src dir includes "exports files" (e.g. src/ol/map.exports). An export file declares symbols and properties that are to be exported when creating builds of the library. For example the src/ol/map.exports file includes this:
|
||||
|
||||
```
|
||||
@exportClass ol.Map ol.MapOptions
|
||||
@exportProperty ol.Map.prototype.getControls
|
||||
```
|
||||
|
||||
|
||||
This declares that the `ol.Map` symbol, and that the `ol.Map.prototype.getControls` property, should be exported, i.e. made available to lib users.
|
||||
|
||||
Exports files are processed by the `bin/generate-exports` script, using its `--exports` switch. This script receives a list of exports files as its input, and outputs `@exportSymbol` and `@exportProperty` statements. The `Makefile` places the output of the `generate-exports --exports` command in the `build/src/external/src/exports.js` file. This js file is then used as an input file for the `ol.js` build (see `build/ol.json`).
|
||||
|
||||
Note: the `src/google.exports` file just makes the `goog.require` function be exported as a null function. This is just to be able to execute the examples both in dev mode (mode=RAW) – where `goog.require` statements are required – and with the `ol.js` build.
|
||||
|
||||
The `src/objectlitterals.exports` file is specific. This file declares the config objects and properties for single-arg constructors. These declarations are done with the `@exportObjectLitteral` and `@exportObjectLitteralProperty` directives. This file is also processed with the `bin/generate-exports` script, but using the `--externs` and `--typedef` switches. The `generate-exports --externs` generates Closure externs from the `@exportObjectLitteral` and `@exportObjectLitteralProperty` directives. The Makefile places these externs in the `build/src/external/externs/types.js` file, which is used as a regular externs file by the Closure compiler (see `build/ol.json`). The `generate-exports --typedef` command generate typedef's for the object litterals declared with @exportObjectLitteral and `@exportObjectLitteralProperty`. The `Makefile` places the typedef's in the `build/src/external/src/types.js`, which, like `exports.js`, is used as an input file for the ol.js build (see `build/ol.json`). Externs define types for config objects created by lib users, while typedef's define types created internally by the lib.
|
||||
|
||||
OL3 devs need to create new exports files when adding new API elements to the lib. They also need to declare single-arg constructors' config objects and properties in `src/objectlitterals.exports`.
|
||||
Reference in New Issue
Block a user