Here's an example of some code I picked up for an Angular2 tutorial by Max Schwarzmueller on YouTube: https://www.youtube.com/playlist?list=PL55RiY5tL51olfU2IEqr455EYLkrhmh3n.
import {Injectable} from "angular2/core";
import {CONTACTS} from "./mock-contact";
@Injectable()
export class ContactService {
getContacts() {
return Promise.resolve(CONTACTS);
}
insertContact(contact: Contact) {
Promise.resolve(CONTACTS)
.then(
(contacts: Contact[]) => contacts.push(contact)
);
}
}
In this example, the CONTACTS object is static JSON. A promise isn't necessary here, but was used to show usage of a service in the real world.
I pretty much understand it, but I'm trying to migrate this idea into a service where I'm using an observable instead of a promise.
I want to make a change to the CONTACTS array, and then have the Observable emit .then again to tell all the observers to do their thing one more time.
On an observable, what would be analogous to Promise.resolve here? The documentation for RxJS observables is a lot to wade through.
If this is just a dumb idea, or there's a better way, please let me know.