Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve .resolve behavior #113

Open
MichaelHirn opened this issue Sep 13, 2019 · 0 comments
Open

Improve .resolve behavior #113

MichaelHirn opened this issue Sep 13, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request refactor rlay-client-lib issues pertaining to @rlay/rlay-client-lib
Milestone

Comments

@MichaelHirn
Copy link
Contributor

.resolve, introduced with v0.2.0, fetches class, data, and object assertions (property and assert assertions) for an individual, decodes them, and attaches them to the individual so that they can be accessed via entity.customNameOfTheSchemaAssertion.

Many methods, especially those from higher-level factories like those introduced by rlay-ontology packages, require that individual was resolved first. However, there is no single mechanism to check if an entity is resolved or not, which leads at its best to ugly and non-obvious code. E.g.

if (entity.properties instanceof Object) {
  await entity.resolve()
}

There are also several related issues, such as mental overhead when coding to keep in mind if an entity is resolved at that instance, or in another route run-time overhead when a resolved entity is resolved again, etc.

Solutions

smart resolve

A simple solution would be to add a entity.isResolved() method which is just a nice way to basically do what the non-obvious code from above does. Then update entity.resolve() to only call out to rlay-client if entity.isResolved() is false. This makes calling entity.resolve() cheap reduces boilerplate to a minimum. However, .resolve would need a forceFlag so that a resolve can be triggered when for example the entity has received more assertions in the meantime. This can be limited to only needing to call entity.resolve({force: true}) when an application elsewhere might have asserted something about the entity, by integrating .resolve into .assert. However, this might needs more thought.

ResolvedEntity class

A potentially more elegant solution where any Individual can be cast into a ResolvedIndividualEntity, which must not come with the core rlay-client-lib. Might have similar logic to the first smart resolve proposal. I think smart resolve might be the better way to go here, at least for now, as .resolve is so often used and core.

@MichaelHirn MichaelHirn self-assigned this Sep 13, 2019
@MichaelHirn MichaelHirn added refactor rlay-client-lib issues pertaining to @rlay/rlay-client-lib enhancement New feature or request labels Sep 13, 2019
@MichaelHirn MichaelHirn added this to the v0.3.0 milestone Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor rlay-client-lib issues pertaining to @rlay/rlay-client-lib
Projects
None yet
Development

No branches or pull requests

1 participant