1- import { Component , OnInit < % if ( filters . socketio ) { % > , OnDestroy< % } % > } from '@angular/core' ;
1+ import { Component , OnInit < % if ( filters . ws ) { % > , OnDestroy< % } % > } from '@angular/core' ;
22import { Http } from '@angular/http' ;
33import { Observable } from 'rxjs/Observable' ;
44import { SocketService } from '../../components/socket/socket.service' ;
@@ -8,34 +8,34 @@ import { SocketService } from '../../components/socket/socket.service';
88 template : require ( './main.<%=templateExt%>' ) ,
99 styles : [ require ( './main.<%=styleExt%>' ) ] ,
1010} )
11- export class MainComponent implements OnInit < % if ( filters . socketio ) { % > , OnDestroy < % } % > {
12- < % _ if ( filters . socketio ) { - % >
11+ export class MainComponent implements OnInit < % if ( filters . ws ) { % > , OnDestroy < % } % > {
12+ < % _ if ( filters . ws ) { - % >
1313 SocketService ; < % } % >
1414 awesomeThings = [ ] ;
1515 < % _ if ( filters . models ) { - % >
1616 newThing = '' ; < % } % >
1717
1818 < % _ if ( filters . babel ) { - % >
1919 static parameters = [ Http , SocketService ] ; < % } % >
20- constructor(< %= private ( ) % > http: Http< % if ( filters . socketio ) { % > , < %= private ( ) % > socketService: SocketService< % } % > ) {
20+ constructor(< %= private ( ) % > http: Http< % if ( filters . ws ) { % > , < %= private ( ) % > socketService: SocketService< % } % > ) {
2121 this . Http = http ;
22- < % _ if ( filters . socketio ) { - % >
22+ < % _ if ( filters . ws ) { - % >
2323 this . SocketService = socketService ; < % } %>
2424 }
2525
2626 ngOnInit ( ) {
2727 this . Http . get ( '/api/things' )
2828 . map ( res => {
2929 return res . json ( ) ;
30- < % _ if ( filters . socketio ) { - % >
31- // this.SocketService.syncUpdates('thing', this.awesomeThings);<% } %>
3230 } )
3331 . catch ( err => Observable . throw ( err . json ( ) . error || 'Server error' ) )
3432 . subscribe ( things => {
3533 this . awesomeThings = things ;
34+ < % _ if ( filters . ws ) { - % >
35+ this . SocketService . syncUpdates ( 'thing' , this . awesomeThings ) ; < % } % >
3636 } ) ;
3737 } < % if ( filters . models ) { % >
38- < % _ if ( filters . socketio ) { % >
38+ < % _ if ( filters . ws ) { % >
3939
4040 ngOnDestroy ( ) {
4141 this . SocketService . unsyncUpdates ( 'thing' ) ;
@@ -50,7 +50,7 @@ export class MainComponent implements OnInit<% if(filters.socketio) { %>, OnDest
5050 . map ( res => res . json ( ) )
5151 . catch ( err => Observable . throw ( err . json ( ) . error || 'Server error' ) )
5252 . subscribe ( thing => {
53- this . awesomeThings . push ( thing ) ;
53+ console . log ( 'Added Thing:' , thing ) ;
5454 } ) ;
5555 }
5656 }
@@ -60,7 +60,7 @@ export class MainComponent implements OnInit<% if(filters.socketio) { %>, OnDest
6060 . map ( res => res . json ( ) )
6161 . catch ( err => Observable . throw ( err . json ( ) . error || 'Server error' ) )
6262 . subscribe ( ( ) => {
63- this . awesomeThings . splice ( this . awesomeThings . findIndex ( el => el . _id === thing . _id ) , 1 ) ;
63+ console . log ( 'Deleted Thing' ) ;
6464 } ) ;
6565 } < % } % >
6666}
0 commit comments