PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/endpoint/templates/name.socket(socketio).js

https://gitlab.com/javajamesb08/generator-angular-fullstack
JavaScript | 24 lines | 16 code | 5 blank | 3 comment | 0 complexity | 7175018a1245f596526f075997f55c8b MD5 | raw file
  1. /**
  2. * Broadcast updates to client when the model changes
  3. */
  4. 'use strict';
  5. var <%= classedName %> = require('./<%= name %>.model');
  6. exports.register = function(socket) {
  7. <%= classedName %>.schema.post('save', function (doc) {
  8. onSave(socket, doc);
  9. });
  10. <%= classedName %>.schema.post('remove', function (doc) {
  11. onRemove(socket, doc);
  12. });
  13. }
  14. function onSave(socket, doc, cb) {
  15. socket.emit('<%= name %>:save', doc);
  16. }
  17. function onRemove(socket, doc, cb) {
  18. socket.emit('<%= name %>:remove', doc);
  19. }