Provider/server: Provide the data or contain the data?

In general, although it is a very common idiom, I think storing raw data in providers is a bad idea, and storing it in a publicly accessible property is a colossal mistake. Here’s why.

Virtually every provider is getting information from some asynchronous external source, and consumers of that provider have no reliable way of knowing when that operation has completed and the data is in a reliable state. At least if the property is private, the provider can ensure reliability in a getter function, but it will be a (relatively needlessly) complex one. If the property is public, you are SOL and just begging for unreproducible race condition bugs.

If the data is loaded only rarely, such as user preferences coming out of storage, then exposing the data as a Promise is one option that solves the reliability sequencing problem: there is an example of this in this thread. If it’s more like a typical get-something-from-REST-backend request, then I think it makes more sense to have a function returning a Promise or Observable of a typed business interface.