angular-resource-sails / angular-resource-sails Goto Github PK
View Code? Open in Web Editor NEWAngular service for managing Sails socket.io connections
Angular service for managing Sails socket.io connections
Running .query() with only an id parameter like so
sailsResource('item').query({ id: 1 })
results in the following response:
[{
"0": "T",
"1": "e",
"2": "s",
"3": "t"
},
{
"0": "2",
"1": "0",
"2": "1",
"3": "6",
"4": "-",
"5": "0",
"6": "3",
"7": "-",
"8": "0",
"9": "3",
"10": "T",
"11": "1",
"12": "8",
"13": ":",
"14": "0",
"15": "8",
"16": ":",
"17": "3",
"18": "6",
"19": ".",
"20": "2",
"21": "9",
"22": "1",
"23": "Z"
},
{
"0": "2",
"1": "0",
"2": "1",
"3": "6",
"4": "-",
"5": "0",
"6": "3",
"7": "-",
"8": "0",
"9": "5",
"10": "T",
"11": "0",
"12": "9",
"13": ":",
"14": "2",
"15": "6",
"16": ":",
"17": "5",
"18": "4",
"19": ".",
"20": "4",
"21": "1",
"22": "3",
"23": "Z"
}]
query() assumes getting an array and instead it gets an object because I only supplied an id.
I think there are multiple ways to solve this.
3 and 4 are kind of the same but in 3 the users gets an array returned and in 4 an object. So the question is: If the user calls query() does she expects always an array or is returning an single object okay, too?
Hello,
I'm facing this error randomly on firefox :
Error: [$rootScope:inprog] http://errors.angularjs.org/1.4.3/$rootScope/inprog?p0=%24digest J/<@http://localhost:1337/js/dependencies/angular.min.js:6:416 r@http://localhost:1337/js/dependencies/angular.min.js:127:187 jf/this.$get</n.prototype.$apply@http://localhost:1337/js/dependencies/angular.min.js:135:200 handleResponse@http://localhost:1337/js/dependencies/sailsResource.js:222:5 retrieveResource/<@http://localhost:1337/js/dependencies/sailsResource.js:294:6 serverResponded@http://localhost:1337/js/dependencies/sails.io.js:282:11 [5]</Socket.prototype.onack@http://localhost:1337/js/dependencies/sails.io.js:3:11417 [5]</Socket.prototype.onpacket@http://localhost:1337/js/dependencies/sails.io.js:3:10590 [7]</module.exports/<@http://localhost:1337/js/dependencies/sails.io.js:3:13699
I think this is because the code call $rootScope.$apply without checking if angular js is in digest phase.
According to this SO post. The library should call $timeout.
I was working on a pull requests that replace $apply calls by $timeout ones but the tests are failing and I don't get why.
Maybe someone has an idea.
Thank you very muck
Error callback are never called even if there was an error. (Using sails.js v0.11).
I dug into the code and according to the sails.js documentation the callback need to take 2 arguments :
In the library at the moment only the first argument is captured and given to handleResponse
. This way the function cannot access the statusCode
and potential errors because they are not in the body.
There might be several solution to this problem. I implemented one in a pull request.
Best,
Guillaume Leclerc
If I make a query() call, I am returned an array of objects.
If at a later point these objects are modified on my backend, I get a $sailsResourceUpdated message but the resources them selves are not modified on the frontend.
Thank you for such a great resource wrapper. It saves time on manually handling socket events.
What is the proper way to submit a Date field? I'm using moment
, but native JS Date object is fine.
Thanks in advance,
Pavel.
such as Model.query({id :hisIds}, success,fail);
When i try to query data by many ids, it will get error. I doubt why you don't support this usage.
Hello,
I just wanted to know if there is any kind of fallbacks if the client does not support socket.io ?
Thank you very much for your answer (and for your project ;) )
Guillaume Leclerc
I created a new model instance as described in the documentation. When i call $save and pass a success callback there is no id, createdAt or updatedAt in the response object:
newItem.$save(function(response) {
// response has no id, createdAt or updatedAt
});
I tracked this down to https://github.com/angular-resource-sails/angular-resource-sails/blob/master/src/sailsResource.js#L334
handleResponse expects a JWR Object with body attribute but it gets directly passed the body attribute. I think a simple fix is to change
socket[method](url, data, function (response) {
to
socket[method](url, data, function (resData, response) {
Like it is done here https://github.com/angular-resource-sails/angular-resource-sails/blob/master/src/sailsResource.js#L288 and here https://github.com/angular-resource-sails/angular-resource-sails/blob/master/src/sailsResource.js#L369
What do you think?
Error callback never gets fired, even if the resource is pointing to a non existing endpoint, even though the server responds with 404 codes (seen in WebSocket communication).
Steps to reproduce:
Can we do something about it? Thanks in advance
there's no way to specific a the url for the sails.io connection.
Hi there,
thanks a lot for this really neat piece of software.
I just stumbled over this error:
TypeError: Cannot read property 'error' of undefined at sailsResource.js:212
Which is (in function handleResponse(item, data, action, deferred, delegate)
):
if (data.error || data.statusCode > 400 || isString(data)) {
I just changed that to:
if (data && (data.error || data.statusCode > 400 || isString(data))) {
I'm not that deep into this module. I hope this is the correct solution.
Hi,
The transformRequest
and transformResponse
for GET action need to be run when socketUpdateResource
function run. The solution worked for me is to update line 402 to retrieveResource(cacheItem, tmp, actions.get);
Is there other way to specify URL to sails server?
I have several apps using the same Sails API and origin parameter works well. I have rolled back to 1.1.4, but if you have a minute, can you please tell what is reason to remove this feature and is it planned to be in future versions?
And thanks, angular-resource-sails is really great lib.
I tried to catch the 400 status code from my backend, but have got 'success' in $save()
What I'm doing:
angular.config(function config ($sailsProvider, sailsResourceProvider) {
// ...
$sailsProvider.urlPrefix = '/api'
sailsResourceProvider.configuration = {
verbose: true
}
// ...
})
// ...
export class ScenarioListController {
constructor ($sails, sailsResource) {
`ngInject`
const Scenario = sailsResource('scenarios', {}, {
socket: $sails // important! passing $sails (SailsSocket) instance as 'socket' option
})
this.scenarios = Scenario.query()
}
// ...
}
// ...
<md-list-item ng-repeat="scenario in ctrl.scenarios">
{{ scenario.name }}
<!-- ... -->
</md-list-item>
What I'm getting every time I open ScenarioListController route (error repeats several times):
Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.4.9/$rootScope/inprog?p0=%24digest
at angular.js:68
at beginPhase (angular.js:16608)
at Scope.$apply (angular.js:16349)
at SailsSocket.<anonymous> (sailsResource.js:93)
at Scope.$eval (angular.js:16251)
at Scope.$digest (angular.js:16069)
at Scope.$apply (angular.js:16359)
at done (angular.js:10791)
at completeRequest (angular.js:10989)
at XMLHttpRequest.requestLoaded (angular.js:10930)
As a current workaround I'm wrapping sailsResource() calls inside a $timeout:
$timeout(() => {
const Scenario = sailsResource('scenarios', {}, { socket: $sails })
this.scenarios = Scenario.query()
})
Also I checked that without angular-sails module with same setup everything works fine (without $timeout wrapping).
Hello,
I have a model User
who have notifications. I created a User resource. The correct request to retrieve notifications using sails is : /user/:id/notifications
. This is a GET request. I was expecting to do something like this :
var User = sailsResource("user", ....);
var me = User.get({id : "me"});
var notifications = me.$notifications();
But because the notification is a GET request (see) I have to do this (which I think is not the optimal way) :
var User = sailsResource("user", ....);
var me = User.get({id : "me"});
var id = me.id;
var notifications = User.$notifications({id : id});
Do you think we could/should add an option (called static
for example) instead of relying on the HTTP method ?
Thank you again for your very useful project !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.