Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. define(['durandal/app'], function (app) {
  2.  
  3. var message = ko.observable();
  4. var canPublish = ko.computed(function () {
  5. return message() ? true : false;
  6. });
  7.  
  8. return {
  9. message: message,
  10. canPublish:canPublish,
  11. publish: function () {
  12. app.trigger('sample:event', message());
  13. }
  14. };
  15. });
  16.  
  17. define(['durandal/app'], function (app) {
  18.  
  19. return {
  20. received: ko.observableArray([]),
  21. subscription:ko.observable(),
  22. subscribe: function () {
  23. var sub = app.on('sample:event').then(function(message) {
  24. this.received.push(message);
  25. }, this);
  26.  
  27. this.subscription(sub);
  28. },
  29. unsubscribe: function () {
  30. this.subscription().off();
  31. this.subscription(null);
  32. }
  33. };
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement