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

💡 Add a get method #43

Open
pjechris opened this issue May 28, 2023 · 0 comments
Open

💡 Add a get method #43

pjechris opened this issue May 28, 2023 · 0 comments
Labels
feature New feature or request

Comments

@pjechris
Copy link
Owner

pjechris commented May 28, 2023

Summary

Today we have find methods which returns a successful observer only if the value is already stored.

Idea would be to add a get counterpart which would always suceeds. This would allow to declare an observer even if the value is not yet present.

To be consistent find(named:) would be renamed get(named:) as aliases never fail

Basic Example

identityMap.find(Foo.self, id: 1) // returns nil because value is not stored yet
identityMap.get(Foo.self, id: 1) // returns an Observer even if value is not stored. Might never receive any value if Foo(id:1) is never stored

identityMap.store(Foo(id: 1, title: "hello world")) // observer is notified

Unresolved questions

Implementing such feature would require refactoring on how observers are handled currently: for now observer is tightly tied with the presence of the value in IdentityMap.

We would need a way of declaring such an observer even when value is not stored yet.

@pjechris pjechris added the feature New feature or request label May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant