Created
May 6, 2015 09:07
-
-
Save gre/fadd75d340f183444e44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import World from "./World"; | |
import Physics from "./Physics"; | |
// expose all the things | |
window.ENGINE = { World: World, Physics: Physics }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Physics = { | |
applyForce: function(x, y) { ... }, | |
processEntity: function(entity) { ... } | |
}; | |
export default Physics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const World = { | |
the_answer_to_everything: 42 | |
}; | |
export default World; |
That was what the with statement did and it's really not recommended:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with
You can inherit the ENGINE methods and properties, like this.
var level = ENGINE.extend({
init: function(){
this.Physics.appyForce();
}
});
It looks great until you take a scope of a real 2 millions characters of code game as an example :)
Of course it would not end up like this, because you would care to copy/paste objects in use to import statement. Nevertheless I still find it counter productive.
import { Ghost, Events, Loader, Components, Animation, Assets, MusicPlayer, Music, Observer, Timeouts,
MinPool, Application, Collection, GameCollection, Unit, ShuffleBag, Collider, SimplePlayer, sampler, Timer,
State, Sprite, Particle, Tween, Ejecta, Meteor, Mine, ProximityMine, Smudge, Flare, FlyingText, Explosion,
Bullet, Capsule, Field, Missile, Bomb, Wave, Beam, StaticBeam, BeamEffect, Weapon, Cooldowns,
HyperTrail, Trail, Stars, JumpZone, Ship, ShipsImagesFactory, Factory, Lander, ShipManifest,
ShipWrapper, ShipAi, Turret, Hypercloud, BgDoodle, Robotalk, Face, Menu, Map, Wreck, Wreckage,
Nebula, Collectible, Astronaut, Planet, StockMarket, Asteroid, ShieldHitEffect, NovaEffect, Console, Tutorial,
PlayerController, ShopController, Dialogue, AI, Sun, Shipyard, Navimap, DoodlePlanet, DoodleShip,
Scenario, Creep, DoodleFlare, MysticJumpGate, Generic, Sonar, RepairStation, RepairShip,
ProductionModule, MapLife, MapLifeView, MapLifeViewShip, ShipsPanel, ServicePanel, EventBubble,
WaveCharge, Boss1, EquipmentPanel, Dronarium, TiledExplosion, Drone, SpawnerModule, Crew,
ShipIncomeComponent, TargetInfoComponent, ShipPlanetInfoComponent, TradersGuild,
GuildsComponent, PlayerControllerComponent, HyperspaceComponent, ShipCrewComponent,
ShipBusComponent, PiratesGuild, ShipExplorationComponent, PlanetInfoComponent,
ShipSystemsComponent, TargetingInfoComponent, Encounter, Mission, Storage, Junkyard, Script
} from "./engine"
Putting some hierarchy into code design should greatly reduce these imports to 5-10.
ES6 destructuring makes this nice too - you can pull out bits only when you need them
import Engine from './Engine';
const {Lander, Astronaut, WaveCharge} = Engine;
const {Encouter, Mission, Junkyard} = Engine;
Etc... not sure why Junkyard is part of your engine though ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can explicitely spread the ENGINE object with:
I guess it is the best way you can go with ES6.
It would be great to do
import * from "Physics";
but it is not supported yet AFAIK.