Skip to content

Commit

Permalink
BundleBase.js: @flow
Browse files Browse the repository at this point in the history
Reviewed By: matryoshcow

Differential Revision: D4036938

fbshipit-source-id: 2c151d98f99ab1e325bb07050d0a2c59ee8f4761
  • Loading branch information
Jean Lauliac authored and Facebook Github Bot committed Oct 18, 2016
1 parent 6d3ecbe commit 8e2b1aa
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packager/react-packager/src/Bundler/BundleBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
* 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
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';

const ModuleTransport = require('../lib/ModuleTransport');

class BundleBase {

_assets: Array<mixed>;
_finalized: boolean;
_mainModuleId: mixed | void;
_modules: Array<ModuleTransport>;
_source: ?string;

constructor() {
this._finalized = false;
this._modules = [];
Expand All @@ -26,19 +35,19 @@ class BundleBase {
return this._mainModuleId;
}

setMainModuleId(moduleId) {
setMainModuleId(moduleId: mixed) {
this._mainModuleId = moduleId;
}

addModule(module) {
addModule(module: ModuleTransport) {
if (!(module instanceof ModuleTransport)) {
throw new Error('Expected a ModuleTransport object');
}

return this._modules.push(module) - 1;
}

replaceModuleAt(index, module) {
replaceModuleAt(index: number, module: ModuleTransport) {
if (!(module instanceof ModuleTransport)) {
throw new Error('Expeceted a ModuleTransport object');
}
Expand All @@ -54,11 +63,11 @@ class BundleBase {
return this._assets;
}

addAsset(asset) {
addAsset(asset: mixed) {
this._assets.push(asset);
}

finalize(options) {
finalize(options: {allowUpdates?: boolean}) {
if (!options.allowUpdates) {
Object.freeze(this._modules);
Object.freeze(this._assets);
Expand All @@ -67,7 +76,7 @@ class BundleBase {
this._finalized = true;
}

getSource(options) {
getSource() {
this.assertFinalized();

if (this._source) {
Expand All @@ -82,7 +91,7 @@ class BundleBase {
this._source = null;
}

assertFinalized(message) {
assertFinalized(message?: string) {
if (!this._finalized) {
throw new Error(message || 'Bundle needs to be finalized before getting any source');
}
Expand Down

0 comments on commit 8e2b1aa

Please sign in to comment.