33 */
44var serverInstances = new Meteor . Collection ( null ) ;
55
6- angular . module ( 'angular-meteor' , [ ] )
7- . run ( [ 'ServerAPI' , '$injector' , function ( ServerAPI , $injector ) {
6+ angular . module ( 'angular-meteor' , [ 'angular-meteor.meteor-collection' ] )
7+ . run ( [ 'ServerAPI' , '$injector' , '$rootScope' , function ( ServerAPI , $injector , $rootScope ) {
88 angular . forEach ( ServerAPI . getServerAPIS ( ) , function ( api ) {
99 var instance = $injector . get ( api ) ;
1010 var funcDefs = [ ] ;
@@ -13,7 +13,15 @@ angular.module('angular-meteor', [])
1313 funcDefs . push ( key ) ;
1414 }
1515 }
16- serverInstances . insert ( { name : api , funcDefs : funcDefs } ) ;
16+ var instanceId = serverInstances . insert ( { name : api , funcDefs : funcDefs , properties : [ ] } ) ;
17+
18+ $rootScope . $watch ( function ( ) {
19+ return instance ;
20+ } , function ( ) {
21+ console . log ( 'updating' , instanceId , instance ) ;
22+ serverInstances . update ( { _id : instanceId } , { $set : { properties : instance } } ) ;
23+ } , true ) ;
24+
1725 } ) ;
1826 } ] )
1927 . run ( function ( ) {
@@ -24,6 +32,7 @@ angular.module('angular-meteor', [])
2432 self . added ( 'serverInstances' , id , fields ) ;
2533 } ,
2634 changed : function ( id , fields ) {
35+ console . log ( 'changed' , id , fields ) ;
2736 self . changed ( 'serverInstances' , id , fields ) ;
2837 } ,
2938 removed : function ( id ) {
@@ -37,11 +46,36 @@ angular.module('angular-meteor', [])
3746 handle . stop ( ) ;
3847 } )
3948 } ) ;
49+ } )
50+ . run ( function ( $rootScope , ServerAPI ) {
51+ //var origRun = Meteor._SynchronousQueue.prototype._run;
52+ //
53+ //console.log('replacing run');
54+ //Meteor._SynchronousQueue.prototype._run = function() {
55+ // console.log('running from queue');
56+ // var result = origRun.apply(this, arguments);
57+ // $rootScope.$apply();
58+ // return result;
59+ //};
60+ var Fibers = Npm . require ( 'fibers' ) ;
61+ var origRun = Fibers . prototype . run ;
62+
63+ Fibers . prototype . run = function ( ) {
64+ var result = origRun . apply ( this , arguments ) ;
65+ if ( ! $rootScope . $$phase ) {
66+ var startTime = new Date ( ) ;
67+ $rootScope . $apply ( ) ;
68+ console . log ( 'digest time:' , new Date ( ) - startTime ) ;
69+ }
70+ return result ;
71+ } ;
4072 } ) ;
4173
4274var origBootstrap = angular . bootstrap ;
4375angular . bootstrap = function ( modules , config ) {
44- return origBootstrap ( document , modules , config ) ;
76+ Meteor . startup ( function ( ) {
77+ origBootstrap ( document , modules , config ) ;
78+ } ) ;
4579} ;
4680
4781
0 commit comments