Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

TypeScript: Extract Application interface for reuse #270

Closed
deskoh opened this issue May 6, 2019 · 1 comment
Closed

TypeScript: Extract Application interface for reuse #270

deskoh opened this issue May 6, 2019 · 1 comment

Comments

@deskoh
Copy link

deskoh commented May 6, 2019

Currently the generated app.interface.ts looks something like the following:

export type App = Application<{
  'messages': Message,
  // !code moduleExports // !end
}>;

Propose to extract out the generic type for reuse:

export interface IApplication {
  'messages': Message,
  // !code moduleExports // !end
}

export type App = Application<IApplication>;

For example, using a custom react hooks for feathers-reactive can be written something like:

import { useState, useEffect } from 'react';
import App from 'Feathers';
import { IApplication } from 'app.interface';

// Other service imports

function useFeathersSubscription<T extends keyof IApplication>(serviceName: T, params?: Params) {
  // Assume non-paginated data.
  const [list, setList] = useState([] as IApplication[T][]);

  const service = App.service(serviceName);

  useEffect(() => {
    const subscription = service.watch()
      .find(params)
      .subscribe((results) => {
        // Assume non-paginated data.
        setList(results as IApplication[T][]);
      });

      return () => { subscription.unsubscribe(); };
    }, [service, params]);

  return [list, service];
}
@bitflower
Copy link

That'd be great. I've build a little hack around that but yeah - this abstraction would help. Might give it a shot as PR

@daffl daffl closed this as completed Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants