amedia-user-js
Its goal is to simplify the complexity of logging in and
getting access to user related data.
Usage
Add this project to yours
> npm i @amedia/amedia-user
Setup a listener for the information you need
import {subscribeToUserUpdates} from '@amedia/amedia-user';
subscribeToUserUpdates(['name', 'email'], (attributes) => {
console.log(attributes);
});
Receiving updates
This callback will be called whenever where are any
changes to the properties you have requested, so
be prepared to rerender.
Also, your requested properties might not arrive
all at once. This callback will be called whenever
we get data in from the various services.
Performance
This app aims to be able to deliver a lot of data really
fast. Still, we might need to call several services in
order to get what you need. We do try to cache whenever
this makes sense, please don't ask for data you don't need.
Behind the scenes
There are a few techniques used to avoid overfetching and
fetching multiple times when once would do.
Event-based actions
Much like
node-userdata-browser/userdata-client
did, we utilize events to message that data is being
requested. This allowed us to decouple your request from
the particular instance that will serve it.
This allows us to have this packed loaded by multiple
different components across the page, and only process
the requests one place.
In addition, if the component that's currently processing
requests should be unloaded for whatever reason, one
of the other instances will automatically take over.
Request deduping
Since we now process from a single instance of the package
it's easy to avoid fetching the same resource multiple
times.
Caching
Tha app has got few caching mechanisms, through local storage
and indexeddb