Hi Jeff,
Would you prefer to get my questions and/or remarks here, or in the github repo?
As you asked here, here are my first observations.I get all of those, except HttpNode. Why a different handler for a node server? Angular should be server agnostic right? Or is it some other kind of node?
- Http
- HttpJsonp
- HttpNode
- HttpMock
- HttpFetch TBD
Also websockets seem to be missing. One could argue that's not an http-handler, but still.
I like the fact that observable's are there! that is a really good addition. It will make a lot of code a whole lot simpler! In fact, there are already some really nice communication handlers available for RX already (dom.ajax dom.fromWebSocket, dom.fromWebWorker to name a few) Is the planning to incorporate those?
with kind regardsSander
Hi Jeff,
I inlined too.
General remarks are best here, issues can be created in Github repo is something needs to be tracked.
Good, so conversation like this goes here, actionable items go into github!
As you asked here, here are my first observations.I get all of those, except HttpNode. Why a different handler for a node server? Angular should be server agnostic right? Or is it some other kind of node?
- Http
- HttpJsonp
- HttpNode
- HttpMock
- HttpFetch TBD
I'm not sure what you mean by "server agnostic." The HttpNode library would be the same interface as Http, but used in a nodejs environment, using nodejs http client. Tobias is exploring server-side rendering of Angular applications, which may include executing angular code on a server. In this context, an application could use dependency injection to bind HttpNode (or some other arbitrary Http library) to Http, so all calls to Http would actually be made to HttpNode.
Alright, now it makes sense to me, I forgot that NG2 does also target the server. That’s really really good, I’ll come back on this in a little while ;)
The Http libraries will also be usable outside the context of Angular. Http should provide nice testing with DI, and nice ergonomics otherwise.
That is a solid base to build on. It also makes it easier to swap out the communications layer. All wins.
Also websockets seem to be missing. One could argue that's not an http-handler, but still.Yeah, a WebSocket implementation is on the radar, and will be observable-based. But it's a completely different beast. I expect within a few weeks I'll post something here about WebSocket implementation.
Good to hear. However, this sounds as the other handlers will work without observables? I think it makes sense to base all communication on observers. That way its way easier to change any part in the system, and also it makes composing the communication stack much easier.
I like the fact that observable's are there! that is a really good addition. It will make a lot of code a whole lot simpler! In fact, there are already some really nice communication handlers available for RX already (dom.ajax dom.fromWebSocket, dom.fromWebWorker to name a few) Is the planning to incorporate those?Glad you're on board with Observables!
This makes us a happy bunch :)
On a serious note, If the data-layer is going to embrace observables, and there is going to be a httpNode interface, it does make a lot of sense to be able to send and receive observeables themselves from client to server. That way communication with the backend will be a seamless part off the application. This is kind of the lower layer of what netflix falcor does. (I know that does a bit more, but it starts with this!)
It will then be very easy to migrate application logic between the server and the client.
I can get deeper into this, but it would help if I know your experience with observables.
Let me give you an example with some pseudo code:
//client:
Observable.fromEvent(submitButton,"click")
.map(pullDataFromForm) // pull the data into the observable
.filter(allDataValid) // function that checks all form data
.toServer('endpointname') // <-- your part ;)
.subscribe(result => alert('data saved on server!'), oops => alert('uhoh?'))
//server:
Observable.createEndpoint('endpointname') // <-- again, your part!
.filter(allDataValid) // server needs to validate too right, why not reuse?
.respond(saveDatatoDbAndAnswerClient) // partly yours, a subscribe method that can respond back to the client.
The kicker, the server can be in the backend, or in the frontend! How do you think about a system like that?
In terms of incorporating those directly in core, it's not likely, but the core should make it simple for developers to incorporate those libraries into their applications. Is there a feature from dom.ajax that you think is worth considering implementing?
If you build the idea I just proposed, I could not care less ;) But just in case I didn’t convince you, I would like to get an observable back from all handlers that has those properties:
For a successful operation, the result will contains the following:
For a failed operation, the result will contain the following:
This might look familiar to you if you browsed trough the RX documentation ;)
Regards
Sander
Hi Rob,
I do like fetch, and it’s an huge improvement over XMLHttpRequest. But as an interface it is almost equal to $http from angular 1, with as addition it can carry more kinds of data beside JSON.
Shouldn’t we do better in NG2?
Observables bring just that to the table. They will make it possible to abstract any kind off communications into a single interface. Interceptors will disappear. You don’t need those any longer.
an example:
let comm = observable.fromWebSocket('someUrl') //pretend that this is a kind of stock ticker
comm
.filter(userHasIntersest) // a function to checks if this msg is important to me
.filter(checkIfNeeded) // is this a msg that is of interst to this routine
.map( msg => msg.currentValue) // I just need the value, so I'm mapping that out
.subscribe(updateScreenValue) // a function that takes an value, and puts it on a display somewhere
comm
.filter(needUserData) // function that checks if the other side needs some extra data
.subscribe(question => {
showModal(question).then( answer => {
comm.onNext({id:question.id,answer:answer})
}
})
This is not even pseudo code, if you fill in the missing functions, this will actually work already!
You can imagine that if you switch to another form off communication, that re-factoring this, is not too much work.
Sure, you have to create the observables that handles the communication, but the code stay’s exactly the same.
in stead of websockets, you can use longpolling or streams or whatever bidirectional communication you fancy . makes no difference to this code.
Regards
Sander
--
You received this message because you are subscribed to the Google Groups "angular-data-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular-data-d...@googlegroups.com.
To post to this group, send email to angular-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular-data-dev/cb7442b0-c25c-47d8-8485-2b57dc4f62ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Jeff,
I inlined too.
General remarks are best here, issues can be created in Github repo is something needs to be tracked.Good, so conversation like this goes here, actionable items go into github!
As you asked here, here are my first observations.I get all of those, except HttpNode. Why a different handler for a node server? Angular should be server agnostic right? Or is it some other kind of node?
- Http
- HttpJsonp
- HttpNode
- HttpMock
- HttpFetch TBD
I'm not sure what you mean by "server agnostic." The HttpNode library would be the same interface as Http, but used in a nodejs environment, using nodejs http client. Tobias is exploring server-side rendering of Angular applications, which may include executing angular code on a server. In this context, an application could use dependency injection to bind HttpNode (or some other arbitrary Http library) to Http, so all calls to Http would actually be made to HttpNode.Alright, now it makes sense to me, I forgot that NG2 does also target the server. That’s really really good, I’ll come back on this in a little while ;)
The Http libraries will also be usable outside the context of Angular. Http should provide nice testing with DI, and nice ergonomics otherwise.That is a solid base to build on. It also makes it easier to swap out the communications layer. All wins.
Also websockets seem to be missing. One could argue that's not an http-handler, but still.Yeah, a WebSocket implementation is on the radar, and will be observable-based. But it's a completely different beast. I expect within a few weeks I'll post something here about WebSocket implementation.Good to hear. However, this sounds as the other handlers will work without observables? I think it makes sense to base all communication on observers. That way its way easier to change any part in the system, and also it makes composing the communication stack much easier.
I like the fact that observable's are there! that is a really good addition. It will make a lot of code a whole lot simpler! In fact, there are already some really nice communication handlers available for RX already (dom.ajax dom.fromWebSocket, dom.fromWebWorker to name a few) Is the planning to incorporate those?Glad you're on board with Observables!This makes us a happy bunch :)
On a serious note, If the data-layer is going to embrace observables, and there is going to be a httpNode interface, it does make a lot of sense to be able to send and receive observeables themselves from client to server. That way communication with the backend will be a seamless part off the application. This is kind of the lower layer of what netflix falcor does. (I know that does a bit more, but it starts with this!)
It will then be very easy to migrate application logic between the server and the client.I can get deeper into this, but it would help if I know your experience with observables.
Let me give you an example with some pseudo code://client: Observable.fromEvent(submitButton,"click") .map(pullDataFromForm) // pull the data into the observable .filter(allDataValid) // function that checks all form data .toServer('endpointname') // <-- your part ;) .subscribe(result => alert('data saved on server!'), oops => alert('uhoh?')) //server: Observable.createEndpoint('endpointname') // <-- again, your part! .filter(allDataValid) // server needs to validate too right, why not reuse? .respond(saveDatatoDbAndAnswerClient) // partly yours, a subscribe method that can respond back to the client.The kicker, the server can be in the backend, or in the frontend! How do you think about a system like that?
--
You received this message because you are subscribed to the Google Groups "angular-data-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular-data-d...@googlegroups.com.
To post to this group, send email to angular-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular-data-dev/9ae1b89b-805f-487a-ba19-e4223ec5597a%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to angular-data-dev+unsubscribe@googlegroups.com.
To post to this group, send email to angular-data-dev@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular-data-dev/20BE66C1-D3E0-4449-9A96-B5071C0D73C8%40gmail.com.
--
Observables will be pervasive in Angular 2 Data, and Angular 2 in general. Though there are still some core promise-based APIs, like in the compiler. As libraries are developed for WebSockets, browser storage, etc, observables will be the main wrapper for data. Is this what you were referring to by "other handlers"?
//client: Observable.fromEvent(submitButton,"click") .map(pullDataFromForm) // pull the data into the observable .filter(allDataValid) // function that checks all form data .toServer('endpointname') // <-- your part ;) .subscribe(result => alert('data saved on server!'), oops => alert('uhoh?')) //server: Observable.createEndpoint('endpointname') // <-- again, your part! .filter(allDataValid) // server needs to validate too right, why not reuse? .respond(saveDatatoDbAndAnswerClient) // partly yours, a subscribe method that can respond back to the client.The kicker, the server can be in the backend, or in the frontend! How do you think about a system like that?
Well I think there's no reason why code couldn't be shared between client and server in this context. It's outside the scope of the http library to facilitate this. This library is pretty low-level, not meant to be too smart.
And though we're exploring node support as a reference for server-side rendering, we aren't necessarily looking to standardize on any particular server as we explore the Angular 2 Data design.
The benefit of reducing the scope of the http() call is that it reduces the complexity and burden of the http library, and delegates common operations to the observable implementation. This makes it easier to build and maintain the different variations of http (xhr, fetch, node, jsonp, etc), and to maintain them. But does this create an overall better developer experience? I think it's a little bit more expressive than attaching a transformer to a config and trusting that the library will be called at the right time. And an application's services can be shared just as easily as a shared configs.
Thoughts? Ben Lesh?? You've been quiet in all this discussion about observables.
I don't think we should use fetch. The problem is that fetch does not support cancellation. This is a pretty big hole in functionality, and it is what spawned this epic issue thread on GitHub. https://github.com/whatwg/fetch/issues/27#issuecomment-88980014
--
You received this message because you are subscribed to the Google Groups "angular-data-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular-data-d...@googlegroups.com.
To post to this group, send email to angular-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular-data-dev/fb6cfdca-8e00-42ac-ae3c-c4df70f13d2c%40googlegroups.com.
window.fetch('someurl.json').then(...self.addEventListener('fetch', function(event) {
event.respondWith( //check cache, or use indexedDB, or actually make request to backend...To view this discussion on the web visit https://groups.google.com/d/msgid/angular-data-dev/71A6E904-0BC9-4358-BE0C-F332CD77F5DC%40gmail.com.
// basic use
myPromise.then(doSomething, failureCallback);
myObservable.subscribe(doSomething, failureCallback, doneCallback);
// error handling
myPromise.catch(err => Promise.resolve('continue')).then(x => console.log(x));
myObservable.catch(err => Observable.return('continue')).subscribe(x => console.log(x));
Think of all of the async things you do in web development (here are a few examples):- HTTP (Ajax/JSONP)- Sockets- Animations- DOM events- WorkersOf those, the only one that is suited well to promises is HTTP. Because it's the only async item in that list that deals with just one value. All of the others are going to emit multiple values.
Could you use Promises for, say, DOM events? Sure. But do you really want to allocate a Promise for every mouse move event, keydown, or click? That would be horribly inefficient.
Observables can represent any collection of things over any amount of time (including zero things over no time at all). They can be merged, zipped, concatenated, forked, filtered, mapped, flatMapped, etc. Just like you would with Arrays and something like LoDash. That's not even to speak *anything* of the value added by providing a path to reactive streams. I'm still talking about using them in a very naive way.
So, this statement is liable to escalate the discussion, but I'll put it out there to get people thinking: Allocating a Promise over an Observable offers no real benefit beyond familiarity, and is in fact less beneficial because of what you lose in doing so.
Promises were a great solution and replacement for callbacks as of a few years ago. Imagine if we hadn't gone forward with Promises because callbacks were "easier" or "more familiar"? Staying with Promises over observables poses that same sort of risk, in my mind. Callbacks and promises will still always have their place, in particular callbacks, but in terms of a framework like Angular, I think it's best to lean on the power and compositional nature of Observables as much as possible.
And yes, I'm drinking the Koolaid with a funnel. Because it's the right thing to do.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular-data-dev/feb56790-9466-4131-b2b8-0278de162b87%40googlegroups.com.
Of those, the only one that is suited well to promises is HTTP. Because it's the only async item in that list that deals with just one value. All of the others are going to emit multiple values.