Application Services
This chapter provides documentation to all application services
Pub/Sub Mechanism
DreamFace Applications have a publish & subscribe mechanism developers can use to implement communication between different components:
- Application: subscribe to events that occur on pages or views. Broadcast events toward the hierarchy of application component (pages and views).
- Page: subscribe to events that are broadcasted by the application and emitted by views. Broadcast events to views and emit events to the application.
- Views: subscribe to events that are broadcasted by the application and pages. Emit events to the application and pages. In the future, we may implement that views can Broadcast events to Graphical Controls.
View to View communication: because Views are at the same level on a page, developers need to implement an event at the page level to broadcast events emitted by a View.
Code:
Location: /src/js/angular/dfx.app.services.js
Service Name: dfxPubSub
// To emit/broadcast/subscripe to event from a Page or Application Controller
dfxPubSub.appEmit( 'NewNotification', {'type': 'email', 'title': 'Hello'} );
dfxPubSub.appBroadcast('NewNotification', {'type': 'email', 'title': 'Hello'} );
dfxPubSub.appSubscribe( 'NewNotification', function(event, data) {} );
// To emit/broadcast/subscripe to event from a View
dfxPubSub.viewEmit( $scope, 'NewNotification', {'type': 'email', 'title': 'Hello'} );
dfxPubSub.viewBroadcast( $scope, 'NewNotification', {'type': 'email', 'title': 'Hello'} );
dfxPubSub.viewSubscribe( $scope, 'NewNotification', function(event, data) {} );