Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To structure this overall approach, the OpenLMIS-UI will use a paradigm that was popularized with the AngularJS module ngResource. The ngResource pattern allows for a "data resource" to be created as a singleton, which will then return objects that use the domain language to express changes to an object's state.

Data

...

The ideal first step for any resource factory would be to establish and implement a local database. This change will help the OpenLMIS-UI better fit into the "offline-first" suite of products.

...

Resources

Data resources provide a layer of abstraction between the OpenLMIS Services and the OpenLMIS-UI. These data resources should always be focused on the domain-level object rather than the OpenLMIS Service that provides data for the object.

An example of where the data resource should cover multiple OpenLMIS Services is the "user" data resource. In the OpenLMIS Services, the "user" domain object has the most information available in the openlmis-referencedata service, but a user's password is updated through the openlmis-auth service.

All data resources will be dependency injected, which will allow other modules to add or modify methods exposed by the data resource. Connecting to a OpenLMIS Service should be considered an incremental improvement to the base factory, and these methods should be added with decorators.

A resource shouldn't do anything more than expose actions that would change the state of a domain objectMost data resources will implement a local database so that the resources are available offline, but some resources such as orderables might not have functional requirements to function offline.

Domain Objects

General idea here is that we want our objects to have multiple methods, so that we can always extend an object method. These methods can implement business logic that does validation, or interact with their parent data resource to send data back to the server.

Internally, like ngResource, all domain objects should have a toJSON method that is used to store a domain logic in a local database or send it to an OpenLMIS Service.

These objects will still have properties, which should be directly accessed/mutated in forms.

...