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

How to declare the app in a static way? #86

Closed
ramsestom opened this issue Sep 7, 2016 · 2 comments
Closed

How to declare the app in a static way? #86

ramsestom opened this issue Sep 7, 2016 · 2 comments

Comments

@ramsestom
Copy link

Seems a pretty dumb question but how can I define my feathers client in one javascript file and use it in multiple other files (whithout having to pass it as a variable parametter)

If I do something like this:
server.js

import 'babel-polyfill';
import feathers from 'feathers/client'
import hooks from 'feathers-hooks';
import rest from 'feathers-rest/client'
import authentication from 'feathers-authentication/client';
import localstorage from 'feathers-localstorage';

export default const app = feathers()
        .configure(rest(host).fetch(fetch))
        .configure(hooks())
        .configure(authentication({
            storage: AsyncStorage
        }));

userHandler.js

import {app} from 'server.js;
...
app.service('users').create(userData).then((result) => {
...
}

messageHandler.js

import {app} from 'server.js;
...
app.service('messages').create(messageData).then((result) => {
...
}

appears that the feathersjs app configuration would be rerun at each import call. So is there a way to configure the feathers client in a static way and to reuse it in other javascript files with import (so without having to pass the app as a variable parametter from class to class)?

@daffl
Copy link
Member

daffl commented Sep 7, 2016

That's the way to do it. Imports are only always executed once.

@ramsestom
Copy link
Author

OK. Thanks. I wasn't sure whether the code into server.js would only be executed once or for each import call (so twice here).

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

2 participants