Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Typings don't include configure method #130

Closed
cloudlena opened this issue Dec 21, 2016 · 4 comments · Fixed by #134
Closed

Typings don't include configure method #130

cloudlena opened this issue Dec 21, 2016 · 4 comments · Fixed by #134

Comments

@cloudlena
Copy link

cloudlena commented Dec 21, 2016

I updated to feathers-client 1.8.0 which now includes typings. This broke my build of an Angular 2 app since I couldn't use feathers-client how I used to anymore. I had the following code in the Angular Service (following my own tutorial from https://berndsgn.ch/angular2-and-feathersjs/):

const socket = io(this.url);
const feathersApp = feathers().configure(feathers.socketio(socket));
this.feathersService = feathersApp.service('my-item');

this.feathersService.on('created', (newCheck) => this.created(newCheck));

This isn't valid anymore according to the typescript definitions which only export a FeathersApp and a FeathersService. I tried doing the following:

const socket = io(url);
const feathersApp = new FeathersApp()
this.feathersService = feathersApp.service('my-item');

this.feathersService.on('created', (newCheck) => this.created(newCheck));

but then I wasn't sure where to put the configure part because the typings don't know anything like that. Can you help me out here or is that method really missing from the typings?

@daffl
Copy link
Member

daffl commented Dec 30, 2016

@ninachaubal Would you mind adding .configure(function) into the TS definitions?

@cloudlena
Copy link
Author

@daffl, thanks for including the configure function so quickly. However, I still think that there is some stuff missing for using the typings correctly. Can you please let me know how to rewrite the following code:

import * as io from 'socket.io-client';
import * as feathers from 'feathers-client';

export class MyService {
  private feathersService: any;

  constructor() {
    const socket = io('https://myurl.com');
    const feathersApp = feathers().configure(feathers.socketio(socket));
    this.feathersService = feathersApp.service('my-item');
  }
}

using the typings?

In my opinion, it should be something like

import * as io from 'socket.io-client';
import { FeathersApp, FeathersService, FeathersSocketIO } from 'feathers-client';

export class MyService {
  private feathersService: FeathersService;

  constructor() {
    const socket = io('https://myurl.com');
    const feathersSocket = new FeathersSocketIO(socket);
    const feathersApp = new FeathersApp(feathersSocket);
    this.feathersService = feathersApp.service('my-item');
  }
}

What do you think? Is that more or less correct? Currently I'm getting errors trying it like that so I think we need some more from the typings.

@ninachaubal
Copy link
Contributor

@mastertinner the way I've got this to work is to set up feathers globally outside of the Angular app, like the example in the feathers docs. I have the following in my index.html

<script>
   // Set up feathers.
   var socket = io();
   var app = feathers()
      .configure(feathers.socketio(socket))
      .configure(feathers.hooks())
      .configure(feathers.authentication({ storage: window.localStorage }));
</script>

Then in an Angular service, you can do something like this

import { Injectable } from '@angular/core';
import { FeathersApp, FeathersService } from 'feathers-client'

declare var app: FeathersApp; // This lets you access app from the global namespace

@Injectable()
export class MyService {
    private feathersService: FeathersService;

    constructor() {
        this.feathersService = app.service('my-team')
    }
}

I think we might be able to define the feathers object in the typings and that would let you do the setup in the Angular app. The top level app component might be a good place to put that. To access the socketio io() method in typescript, you are either going to have to add SocketIO typings or you can declare io with type any.

@cloudlena
Copy link
Author

Thanks, @ninachaubal! Declaring and setting up feathers outside of the Angular app is a workaround which I wouldn't want to do. I think, the way to go is what you suggested. To define the feathers object in the typings.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants