You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
Here's an example that works with can-connect. This example is a supermodel created by running donejs add supermodel then adding the realtime stuff and providing the methods for the data-url behavior.
importcanfrom'can';importsuperMapfrom'can-connect/can/super-map/';importtagfrom'can-connect/can/tag/';import'can/map/define/define';importfeathersfrom'feathers-client';importiofrom'steal-socket.io';vartoken='';consturl='http://localhost:8080/';if(window.localStorage){token=window.localStorage.getItem('authToken');}constsocket=io(url,{query: 'token='+token,transports:['websocket']});varapp=feathers(url).configure(feathers.socketio(socket));varprefService=app.service('/preferences');exportconstPreference=can.Map.extend({define: {}});Preference.List=can.List.extend({Map: Preference},{});exportconstpreferenceConnection=superMap({idProp: '_id',Map: Preference,List: Preference.List,name: 'preference',url: {getListData(params){returnnewPromise(function(success,error){returnprefService.find(params,function(err,data){if(err){returnerror(err);}console.log('Found the following data',data);returnsuccess(data);});});},getData(params){returnnewPromise(function(success,error){returnprefService.get(params._id,params,function(err,data){if(err){returnerror(err);}console.log('Got the following data',data);returnsuccess(data);});});},createData(data){console.log(data);returnnewPromise(function(success,error){returnprefService.create(data,function(err,data){if(err){returnerror(err);}console.log('Created data',data);returnsuccess(data);});});},updateData(data){returnnewPromise(function(success,error){returnprefService.update(data,function(err,data){if(err){returnerror(err);}console.log('Updated data',data);returnsuccess(data);});});},destroyData(id){returnnewPromise(function(success,error){returnprefService.remove(id,function(err,data){if(err){returnerror(err);}console.log('Removed data',data);returnsuccess(data);});});}}});tag('preference-model',preferenceConnection);socket.on('preferences created',preference=>preferenceConnection.createInstance(preference));socket.on('preferences updated',preference=>preferenceConnection.updateInstance(preference));socket.on('preferences removed',preference=>preferenceConnection.destroyInstance(preference));exportdefaultPreference;
This will be a lot more elegant once #7 is complete. In this particular case in the app I'm building, I have it checking for a preferences object for the current user on page load. If it doesn’t exist, it creates one, but it all happens before the socket is connected, which will be easy to fix with Promises.
The text was updated successfully, but these errors were encountered:
Promises are now supported in the 0.3.0 release. The plugin is also using ES6 now. Let me know if you run into any issues upgrading the can-connect adapter!
Here's an example that works with can-connect. This example is a supermodel created by running
donejs add supermodel
then adding the realtime stuff and providing the methods for the data-url behavior.This will be a lot more elegant once #7 is complete. In this particular case in the app I'm building, I have it checking for a preferences object for the current user on page load. If it doesn’t exist, it creates one, but it all happens before the socket is connected, which will be easy to fix with Promises.
The text was updated successfully, but these errors were encountered: