balderdashy / balderdashy/sails

Using sails.io pubsub works with shortcuts, but not with RESTful record creation

Open
#4,674 5 comments 0 reactions 0 assignees View on GitHub
docs needs version info
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I don't know if it's a bug.

From stackoverflow:

https://stackoverflow.com/questions/46638471/using-sails-io-pubsub-works-with-shortcuts-but-not-with-restful-record-creation

I test with two instances of my angular 6 app and it's true. If I use the same socket to do the "create" and "to listen" (on method), only works in another instance of my app.

Is it correct? Can we avoid this action? I think that it must be commented in the documentation, because, in my case, I loose a lot of time until I found this comment in stackoverflow.

For the documentation, you can put a example of angular 2+.

I am working with this service:

```
import {Injectable} from '@angular/core';

function _window(): any {
// return the global native browser window object
return window;
}

@Injectable({
providedIn: 'root'
})

export class SocketService {
get ioSails(): any {
return _window().io;
}
}

```
and, in the index.html

```


io.sails.autoConnect = true;
io.sails.url = 'http://localhost:1337';
io.sails.transports = ['websocket'];
io.sails.reconnection = true;

```

And in the components:

```
import { Component, OnInit, NgZone } from '@angular/core';
import { SocketService } from '../services/socket.service';

@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})

export class TestComponent implements OnInit {

public users: any[];

constructor(
private _socketservice: SocketService,
private _zone: NgZone
) {
}

ngOnInit() {

}

example_action() {

console.log('TEST');

this._socketservice.ioSails.socket
.get('/Clientes',
(res) => {
this._zone.run(() => {
this.users = res;
console.log(res);
});

}
);
}
```

All comments about this case are welcome.

Contributor guide

Open the contributing guide

Research direction

Start with the Stack Overflow report linked in the issue and the Angular SocketService, index.html, and component examples shown in the body. Confirm the RESTful record-creation and pubsub behavior, then document the expected result and add an Angular 2+ example; the documentation should answer whether the behavior is correct and how it should be used.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, javascript
Domain
api, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.