diff --git a/Exports-Files.md b/Exports-Files.md index 2f31389..cce892d 100644 --- a/Exports-Files.md +++ b/Exports-Files.md @@ -21,18 +21,30 @@ The `build.py` script places the output of `generate-exports --exports` into the ## Exporting options objects -The `src/objectliterals.exports` file is specific. This file declares the config objects and properties for the library's single-argument constructors. These declarations are done with the `@exportObjectLiteral` and `@exportObjectLiteralProperty` directives. This file is also processed with the `bin/generate-exports` script, but using the `--externs` and `--typedef` switches. +All the (exported) constructors are _single-argument constructors_, they take one argument, `options`, which is a JavaScript literal object. Here's for example how options are passed to the `ol.Map` constructor: -Note: config objects and properties are declared in a specific file because they may be shared by multiple constructors. For example the `ol.source.Vector` constructor currently takes an `ol.source.SourceOptions` config object, and `ol.source.SourceOptions` is a generic/base type that can used for other constructors. -(We may want to change that in the future, and force each constructor to have its own config object type. In this way config objects and properties could be declared in the same exports file as their corresponding constructors.) + var map = new ol.Map({ + layers: [ + new ol.layer.TileLayer({ + source: new ol.source.OSM() + }) + ], + target: 'map' + }); -The `generate-exports --externs` generates Closure externs from the `@exportObjectLiteral` and `@exportObjectLiteralProperty` directives. The `build.py` script 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 constructors` options objects, and their properties, are declared in the `src/objectliterals.jsdoc` file. The options objects themselves are declared using the `@typedef` keyword, while properties are declared using the `@property` keyword. -The `generate-exports --typedef` command generate typedef's for the object literals declared with `@exportObjectLiteral` and `@exportObjectLiteralProperty`. The `build.py` script 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`). +This file is also processed with the `bin/generate-exports` script, but using the `--externs` and `--typedef` switches. -Externs define types for config objects created by library's users, while typedef's define types created internally by the library. +Note: config objects and properties are declared in a specific (separate) file because they may be shared by multiple constructors. For example the `ol.source.Vector` constructor currently takes an `ol.source.SourceOptions` options object, and `ol.source.SourceOptions` is a generic/base type that may be used for other constructors. -OL3 devs and contributors need to create new exports files when adding new API elements to the library. They also need to declare single-arg constructors' config objects and properties in `src/objectliterals.exports`. +Note: We may want to change that in the future, and force each constructor to have its own config object type. In this way config objects and properties could be declared in the same file as their corresponding constructors. + +The `generate-exports --externs` generates Closure externs from the `@typedef` and `@property` directives. The `build.py` script 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 `buildcfg/ol.json`). + +The `generate-exports --typedef` command generate typedef's for the object literals declared with `@typedef` and `@property`. The `build.py` script 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 `buildcfg/ol.json`). + +Externs define types for options objects created by library's users, while typedef's define types created internally by the library. ## Under the hood