PageRenderTime 23ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/example/node/client/js/models/wiretap-model.js

http://github.com/ifandelse/postal.js
JavaScript | 40 lines | 35 code | 5 blank | 0 comment | 0 complexity | 75a91878af1ca728c00c02627808e3b7 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause
  1. define( [
  2. 'backbone',
  3. 'postal'
  4. ],
  5. function ( Backbone, postal ) {
  6. "use strict";
  7. var RawMessage = Backbone.Model.extend({
  8. defaults: {
  9. text: ""
  10. }
  11. });
  12. return Backbone.Collection.extend( {
  13. model: RawMessage,
  14. initialize : function () {
  15. var self = this;
  16. postal.addWireTap(function( data, envelope ){
  17. var text = "";
  18. try {
  19. text = JSON.stringify( envelope );
  20. }
  21. catch ( exception ) {
  22. try {
  23. var env = _.extend( {}, envelope );
  24. delete env.data;
  25. text = JSON.stringify( env ) + "\n\t" + "JSON.stringify Error: " + exception.message;
  26. }
  27. catch ( ex ) {
  28. text = "Unable to parse data to JSON: " + exception;
  29. }
  30. }
  31. self.add({ text: text });
  32. });
  33. }
  34. } );
  35. } );