BundleBase.js: @flow

Reviewed By: matryoshcow

Differential Revision: D4036938

fbshipit-source-id: 2c151d98f99ab1e325bb07050d0a2c59ee8f4761
This commit is contained in:
Jean Lauliac 2016-10-18 10:21:19 -07:00 committed by Facebook Github Bot
parent 6d3ecbe07a
commit 8e2b1aa482
1 changed files with 16 additions and 7 deletions

View File

@ -5,12 +5,21 @@
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/ */
'use strict'; 'use strict';
const ModuleTransport = require('../lib/ModuleTransport'); const ModuleTransport = require('../lib/ModuleTransport');
class BundleBase { class BundleBase {
_assets: Array<mixed>;
_finalized: boolean;
_mainModuleId: mixed | void;
_modules: Array<ModuleTransport>;
_source: ?string;
constructor() { constructor() {
this._finalized = false; this._finalized = false;
this._modules = []; this._modules = [];
@ -26,11 +35,11 @@ class BundleBase {
return this._mainModuleId; return this._mainModuleId;
} }
setMainModuleId(moduleId) { setMainModuleId(moduleId: mixed) {
this._mainModuleId = moduleId; this._mainModuleId = moduleId;
} }
addModule(module) { addModule(module: ModuleTransport) {
if (!(module instanceof ModuleTransport)) { if (!(module instanceof ModuleTransport)) {
throw new Error('Expected a ModuleTransport object'); throw new Error('Expected a ModuleTransport object');
} }
@ -38,7 +47,7 @@ class BundleBase {
return this._modules.push(module) - 1; return this._modules.push(module) - 1;
} }
replaceModuleAt(index, module) { replaceModuleAt(index: number, module: ModuleTransport) {
if (!(module instanceof ModuleTransport)) { if (!(module instanceof ModuleTransport)) {
throw new Error('Expeceted a ModuleTransport object'); throw new Error('Expeceted a ModuleTransport object');
} }
@ -54,11 +63,11 @@ class BundleBase {
return this._assets; return this._assets;
} }
addAsset(asset) { addAsset(asset: mixed) {
this._assets.push(asset); this._assets.push(asset);
} }
finalize(options) { finalize(options: {allowUpdates?: boolean}) {
if (!options.allowUpdates) { if (!options.allowUpdates) {
Object.freeze(this._modules); Object.freeze(this._modules);
Object.freeze(this._assets); Object.freeze(this._assets);
@ -67,7 +76,7 @@ class BundleBase {
this._finalized = true; this._finalized = true;
} }
getSource(options) { getSource() {
this.assertFinalized(); this.assertFinalized();
if (this._source) { if (this._source) {
@ -82,7 +91,7 @@ class BundleBase {
this._source = null; this._source = null;
} }
assertFinalized(message) { assertFinalized(message?: string) {
if (!this._finalized) { if (!this._finalized) {
throw new Error(message || 'Bundle needs to be finalized before getting any source'); throw new Error(message || 'Bundle needs to be finalized before getting any source');
} }