Comments (13)
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.
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.
No. I don't see how websockets fit with the request/response format of the other adapters.
from js-data.
@jmdobry how we can implement 3-way data binding?
- mongodb + nodejs backend (1+ servers)
- multiple angularjs clients
from js-data.
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.
@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.
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.
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.
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.
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.
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.
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.
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)
- 4.0.0 Release
- Record & Schema Classes
- Refactor code to use ecmascript Classes
- Publish all packages under @js-data team/scope
- Lerna mono repo? HOT 3
- Improve relations logic HOT 5
- jsdoc - api docs
- make orderBy work with locality by using Intl.collator
- Maximum call stack size exceeded when related models have different idAttribute
- datastore.get(mapper, '') returns a record (v3)
- Defining relations results to error when the Mapper recordClass is set to false (POJO) HOT 2
- Node6 incompatibilities with `querystrings` HOT 6
- hasOne relations aren't found in store for newly added records
- Hooks not working on mappers
- 🚨 Potential Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution') (CWE-1321) HOT 3
- 🚨 Potential Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution') (CWE-1321) HOT 7
- Trying to get in touch regarding a security issue
- SimpleStore doesn't support eager loading
- Getting 'DSUtils.deepMixIn' undefined when upgrading js-data package. HOT 1
- Lack of redirect from js-data.io to www.js-data.io HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-data.