Giter VIP home page Giter VIP logo

Comments (13)

derekperkins avatar derekperkins commented on May 31, 2024

What would be the recommended solution for integrating a Websocket platform like PubNub or Pusher? Would they need their own adapter? @tannerlinsley

from js-data.

derekperkins avatar derekperkins commented on May 31, 2024

I just saw #44, which appears to handle the use case just fine. Would there still be a benefit to having an adapter ala Firebase?

from js-data.

jmdobry avatar jmdobry commented on May 31, 2024

No. I don't see how websockets fit with the request/response format of the other adapters.

from js-data.

alexzaporozhets avatar alexzaporozhets commented on May 31, 2024

@jmdobry how we can implement 3-way data binding?

  • mongodb + nodejs backend (1+ servers)
  • multiple angularjs clients

from js-data.

jmdobry avatar jmdobry commented on May 31, 2024

With something like this:

var socket = io.connect(app.url, { path: '/api/socket.io' });

  socket.on('create', function (data) {
    if (data.ownerId && $rootScope.loggedInUser && $rootScope.loggedInUser.id === data.ownerId) {
      DS.find(data.resource, data.id);
    }
    $rootScope.$broadcast('create', data.resource, data.id, data.ownerId);
  });
  socket.on('update', function (data) {
    if (data.id === 'all' && data.seriesId) {
      angular.forEach(DS.filter(data.resource, { seriesId: data.seriesId }), function (instance) {
        DS.refresh(data.resource, instance.id);
      });
    } else {
      DS.refresh(data.resource, data.id);
    }
    $rootScope.$broadcast('update', data.resource, data.id, data.ownerId);
  });
  socket.on('destroy', function (data) {
    if (data.id === 'all' && data.lessonId) {
      DS.ejectAll(data.resource, { lessonId: data.lessonId });
    } else {
      DS.eject(data.resource, data.id);
    }
    $rootScope.$broadcast('destroy', data.resource, data.id, data.ownerId);
  });

from js-data.

alexzaporozhets avatar alexzaporozhets commented on May 31, 2024

@jmdobry thanks a lot for the fast reply and I have few more question:

  • where I can get the service side code (js-data + socket.io integration)?
  • how I should do the same for nodejs workers?

from js-data.

jmdobry avatar jmdobry commented on May 31, 2024

where I can get the service side code (js-data + socket.io integration)?

I'm not sure what you mean. I don't have anything for you beyond that example.

how I should do the same for nodejs workers?

Example code in Node:

lib/messageService.js

// ...

function sendMessage(event, resource, instance) {
  // where io is "var io = require('socket.io').listen(server);" in app.js
  var io = container.get('io');
  var message = {
    id: instance.id,
    ownerId: instance.ownerId,
    resource: resource,
    event: event
  };
  if (instance.parentType) {
    message.parentType = instance.parentType;
  }
  if (instance.parentId) {
    message.parentId = instance.parentId;
  }
  if (instance.lessonId) {
    message.lessonId = instance.lessonId;
  }
  io.sockets.emit(event, message);
}

module.exports = {
  sendCreateMessage: function (resource, instance) {
    sendMessage('create', resource, instance);
  },

  sendDestroyMessage: function (resource, instance) {
    sendMessage('destroy', resource, instance);
  },

  sendUpdateMessage: function (resource, instance) {
    sendMessage('update', resource, instance);
  }
};  

Use with a resource:

var Series = DS.defineResource({
    name: 'series',
    table: 'series',

    // ...

    afterCreate: function (Series, series, cb) {
      // ...

      // Broadcast that this series was created
      messageService.sendCreateMessage('series', series);

      // ...
    },

    afterUpdate: function (Series, series, cb) {
      // ...

      // Broadcast that this series was updated
      messageService.sendUpdateMessage('series', series);

      // ...
    },

    afterDestroy: function (Series, series) {
      // ...

      // Broadcast that this series was destroyed
      messageService.sendDestroyMessage('series', series);

      // ...
    }
  });

from js-data.

catogonzalez avatar catogonzalez commented on May 31, 2024

js-data/js-data-angular#147 is exactly what I am looking for: being able to use js-data with an adapter for Cordova SQLitePlugin so that I can use js-data-angular + js-data-sql in an hybrid mobile app. However, the docs say the js-data-sql adapter is not supported in browsers.

Is there a way to use js-data-sql adapter in an hybrid mobile app (angularjs client)?

from js-data.

jmdobry avatar jmdobry commented on May 31, 2024

Actually, I can't remember who it was or where it was, but somebody told me that they were using the js-data-sql adapter in the browser, which I didn't think would work, but apparently was working for this person.

from js-data.

catogonzalez avatar catogonzalez commented on May 31, 2024

Thanks for your reply @jmdobry. If you don't think it would work, then can you give me some directions on how would you implement/patch it to work? If it ends up being a whole project I might have to look for other solution due to a time constraint.

from js-data.

jmdobry avatar jmdobry commented on May 31, 2024

I don't actually have evidence that it doesn't work in the browser, I just never tried it. I think this person who was using js-data-sql in the browser to connect to sqlite for cordova. I'll see if I can find where they mentioned it. I can't actually think of any reason why it wouldn't work.

from js-data.

catogonzalez avatar catogonzalez commented on May 31, 2024

Well, I tried to load js-data-sql in my project and it fails with this:

0     750666   error    Uncaught ReferenceError: module is not defined, http://localhost:8100/lib/js-data/js-data-sql.js, Line: 1
1     750791   error    Uncaught Error: [$injector:modulerr] Failed to instantiate module transale due to:
Error: [$injector:unpr] Unknown provider: DSSqlAdapterProvider

js-data-sql.js, Line: 1 has module.exports =... and there is the 'module' not defined. I don't know anything about Node.js programming but I guess that's a Node specificity that I would need to change to get this adapter to work in the borwser?

from js-data.

jmdobry avatar jmdobry commented on May 31, 2024

You're going to have to have a build step that uses webpack or browserify to package your code for the browser.

from js-data.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.