mirror of
https://github.com/urbit/shrub.git
synced 2024-12-01 06:35:32 +03:00
contact-js: made channel handle onChannelError
This commit is contained in:
parent
bfcaf6468e
commit
0145981542
@ -9,14 +9,7 @@ import { LocalReducer } from '/reducers/local.js';
|
||||
|
||||
class Store {
|
||||
constructor() {
|
||||
this.state = {
|
||||
contacts: {},
|
||||
groups: {},
|
||||
associations: {},
|
||||
permissions: {},
|
||||
invites: {},
|
||||
selectedGroups: []
|
||||
};
|
||||
this.state = this.initialState();
|
||||
|
||||
this.initialReducer = new InitialReducer();
|
||||
this.groupUpdateReducer = new GroupUpdateReducer();
|
||||
@ -28,6 +21,17 @@ class Store {
|
||||
this.setState = () => {};
|
||||
}
|
||||
|
||||
initialState() {
|
||||
return {
|
||||
contacts: {},
|
||||
groups: {},
|
||||
associations: {},
|
||||
permissions: {},
|
||||
invites: {},
|
||||
selectedGroups: []
|
||||
};
|
||||
}
|
||||
|
||||
setStateHandler(setState) {
|
||||
this.setState = setState;
|
||||
}
|
||||
@ -35,6 +39,11 @@ class Store {
|
||||
handleEvent(data) {
|
||||
let json = data.data;
|
||||
|
||||
if ('clear' in json && json.clear) {
|
||||
this.setState(this.initialState());
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(json);
|
||||
this.initialReducer.reduce(json, this.state);
|
||||
this.groupUpdateReducer.reduce(json, this.state);
|
||||
|
@ -13,11 +13,24 @@ export class Subscription {
|
||||
start() {
|
||||
if (api.authTokens) {
|
||||
this.firstRoundSubscription();
|
||||
window.urb.setOnChannelError(this.onChannelError.bind(this));
|
||||
} else {
|
||||
console.error("~~~ ERROR: Must set api.authTokens before operation ~~~");
|
||||
}
|
||||
}
|
||||
|
||||
onChannelError(err) {
|
||||
console.error('event source error: ', err);
|
||||
console.log('initiating new channel');
|
||||
this.firstRoundSubscriptionComplete = false;
|
||||
setTimeout(2000, () => {
|
||||
store.handleEvent({
|
||||
data: { clear : true}
|
||||
});
|
||||
this.start();
|
||||
});
|
||||
}
|
||||
|
||||
subscribe(path, app) {
|
||||
api.bind(path, 'PUT', api.authTokens.ship, app,
|
||||
this.handleEvent.bind(this),
|
||||
|
Loading…
Reference in New Issue
Block a user