-
-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Feathers universal #193
Conversation
@daffl can you spec out a quick example of how this would be used? Is it in conjunction with |
Importing import feathers from 'feathers';
import socketio from 'feathers-socketio';
import hooks from 'feathers-hooks';
import localStorage from 'feathers-localstorage';
import React from 'react';
const app = feathers()
.configure(socketio('http://chat.feathersjs.com'))
.configure(hooks())
// You can register your own services to manage application state
.use('/store', localStorage('storage'));
// Add hooks e.g. for client-side validation
app.service('messages').before({
create(hook, next) {
if(typeof hook.data.message !== 'string') {
return next(new Error('A message needs to be provided'));
}
next();
}
});
class TodoList extends React.Component {
componentDidMount() {
app.service('messages').find().then(messages =>
this.setState({ messages }));
}
render() {
if(!this.state.messages) {
return <div>Loading...</div>;
}
return <ul>{this.state.messages.map(message => <li>{message.text}</li>)}</ul>;
}
} To use the client in Node you'd |
Man this looks awesome!! You'll probably do the same thing in react native: Let's merge this sucker. I want to play!! 😄 On another note, you didn't write |
Not yet. It was just an idea and as an example that you could use services and other Feathers best practises to also manage application state on the client. Working on migrating the REST, SocketIO and Primus clients now. |
wow this is great @daffl, really keen to play around with this, thanks. :) |
@ahdinosaur Thanks for bringing that up! It definitely turned out even better than I expected. Everything should be released now in |
Yay! I'll check it out today! I guess this means that we now no longer need https://github.com/feathersjs/feathers-client. |
We still need a non CommonJS/NPM build. The question is if they should be provided as distributables in their respective repos or consolidated in feathers-client as a dist that includes all the provider clients and probably hooks. The first option makes it a little annoying to get set up in a non CommonJS/NPM environment because you'll have to include a whole bunch of dependencies manually. Namespacing is also trickier than having the // src/client.js
import feathers from 'feathers/client'
import socketio from 'feathers-socketio/client';
import primus from 'feathers-primus/client';
import rest from 'feathers-rest/client';
import hooks from 'feathers-hooks';
Object.assign(feathers, { socketio, primus, rest, hooks });
export default feathers; And then Browserifies that as an UMD module or a global |
@daffl Ya I'm for option 2: |
This pull request adds a client side shim for Express, allowing to use Feathers in non-Node environments like the Browser and React Native to build fully universal applications with Feathers best practises like services and hooks. The Browserified build is around 8k minified and gzipped.
Also adds a
.defaultService
functionality. This will be needed when initializing non-existing services on the client which should then just connect to their configured endpoint as it is already done in feathers-client.Closes #191