Permalink
Browse files

move most of index.js into App.js

  • Loading branch information...
1 parent 400ded7 commit 440839f83fdb3b848430b29b7faf56c00e9b85a1 @Benvie Benvie committed Sep 5, 2012
Showing with 112 additions and 111 deletions.
  1. +111 −0 lib/App.js
  2. +1 −111 lib/index.js
View
111 lib/App.js
@@ -0,0 +1,111 @@
+var Router = require('./router').Router,
+ Window = require('./window'),
+ _App = require('./bindings').App,
+ NativeWindow = require('./bindings').NativeWindow,
+ WindowSettings = require('./settings').WindowSettings,
+ AppSettings = require('./settings').AppSettings;
+
+var _init = require('./bindings').init,
+ decorate = require('./utils').decorate,
+ isObject = require('./utils').isObject,
+ staticRouter = require('./router').staticRouter;
+
+var _createWindow = _App.prototype.createWindow,
+ concat = Array.prototype.concat;
+
+var pipedEvents = ['create', 'minimize', 'maximize', 'fullscreen', 'restore', 'move', 'resize'];
+
+
+module.exports = App;
+
+function App(){
+ var self = this;
+
+ decorate(this, {
+ screenWidth: _App.screenWidth,
+ screenHeight: _App.screenHeight,
+ windows: {},
+ initialized: false,
+ router: new Router(this),
+ init: function init(options){
+ if (this.initialized)
+ throw new Error('AppJS already intiialized');
+
+ _init(new AppSettings(options));
+ this.intialized = true;
+ return this;
+ }
+ });
+
+ this.on('exit',function(){
+ self.exit();
+ process.nextTick(function(){
+ process.kill(process.pid);
+ });
+ });
+};
+
+decorate(App.prototype, [
+ function createWindow(options){
+ if (!this.initialized) {
+ this.init();
+ }
+ var self = this;
+ if (typeof options === 'string') {
+ if (isObject(arguments[1])) {
+ arguments[1].url = options;
+ options = arguments[1];
+ } else {
+ options = { url: options };
+ }
+ }
+ if (!(options instanceof WindowSettings)) {
+ options = new WindowSettings(options);
+ }
+
+ var nativeWindow = _createWindow.call(this, options),
+ window = new Window(nativeWindow);
+
+ nativeWindow.name = options.name;
+ this.windows[options.name] = window;
+
+ nativeWindow.on('close', function(){
+ window.emit('close');
+ delete self.windows[options.name];
+ });
+
+ pipedEvents.forEach(function(event){
+ nativeWindow.pipe(event, window);
+ });
+
+ return window;
+ },
+ function exit(){
+ Object.keys(this.windows).forEach(function(name){
+ var window = this.windows[name];
+ if (window && window.close) {
+ window.close();
+ }
+ }, this);
+ },
+ function serveFilesFrom(root){
+ this.router.use(staticRouter(root));
+ return this;
+ },
+ function on(type, listener){
+ process.on('appjs-'+type, listener.bind(this));
+ }
+]);
+
+
+
+NativeWindow.prototype.__proto__ = process.EventEmitter.prototype;
+
+decorate(NativeWindow.prototype, [
+ function pipe(event, target){
+ var emit = target.emit;
+ this.on(event, function(){
+ emit.apply(target, concat.apply(event, arguments));
+ });
+ }
+]);
View
112 lib/index.js
@@ -2,116 +2,6 @@ if (typeof Proxy !== 'object' || typeof WeakMap !== 'function') {
throw new Error ('AppJS requires Node is run with the --harmony command line flag');
}
-
-
-var Router = require('./router').Router,
- Window = require('./window'),
- _App = require('./bindings').App,
- NativeWindow = require('./bindings').NativeWindow,
- WindowSettings = require('./settings').WindowSettings,
- AppSettings = require('./settings').AppSettings;
-
-var _init = require('./bindings').init,
- decorate = require('./utils').decorate,
- isObject = require('./utils').isObject,
- staticRouter = require('./router').staticRouter;
-
-
-var concat = Array.prototype.concat,
- _createWindow = _App.prototype.createWindow;
-
-var events = ['create', 'minimize', 'maximize', 'fullscreen', 'restore', 'move', 'resize'];
-
-
-
-NativeWindow.prototype.__proto__ = process.EventEmitter.prototype;
-
-decorate(NativeWindow.prototype, [
- function pipe(event, target){
- var emit = target.emit;
- this.on(event, function(){
- emit.apply(target, concat.apply(event, arguments));
- });
- }
-]);
-
-function App(){
- var self = this;
-
- decorate(this, {
- screenWidth: _App.screenWidth,
- screenHeight: _App.screenHeight,
- windows: {},
- initialized: false,
- router: new Router(this),
- init: function init(options){
- if (this.initialized)
- throw new Error('AppJS already intiialized');
-
- _init(new AppSettings(options));
- this.intialized = true;
- return this;
- }
- });
-
- this.on('exit',function(){
- self.exit();
- process.nextTick(function(){
- process.kill(process.pid);
- });
- });
-};
-
-decorate(App.prototype, [
- function createWindow(options){
- if (!this.initialized) {
- this.init();
- }
- var self = this;
- if (typeof options === 'string') {
- if (isObject(arguments[1])) {
- arguments[1].url = options;
- options = arguments[1];
- } else {
- options = { url: options };
- }
- }
- if (!(options instanceof WindowSettings)) {
- options = new WindowSettings(options);
- }
-
- var nativeWindow = _createWindow.call(this, options),
- window = new Window(nativeWindow);
-
- nativeWindow.name = options.name;
- this.windows[options.name] = window;
-
- nativeWindow.on('close', function(){
- window.emit('close');
- delete self.windows[options.name];
- });
-
- events.forEach(function(event){
- nativeWindow.pipe(event, window);
- });
-
- return window;
- },
- function exit(){
- Object.keys(this.windows).forEach(function(name){
- var window = this.windows[name];
- if (window && window.close) {
- window.close();
- }
- }, this);
- },
- function serveFilesFrom(root){
- this.router.use(staticRouter(root));
- return this;
- },
- function on(type, listener){
- process.on('appjs-'+type, listener.bind(this));
- }
-]);
+var App = require('./App');
module.exports = new App;

0 comments on commit 440839f

Please sign in to comment.