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

Map::update does not play well with GCounter::inc #123

Open
Kiiyya opened this issue Aug 28, 2021 · 0 comments
Open

Map::update does not play well with GCounter::inc #123

Kiiyya opened this issue Aug 28, 2021 · 0 comments

Comments

@Kiiyya
Copy link

Kiiyya commented Aug 28, 2021

It seems like the intended way to use the Map::update function is to use the context given in the closure, e.g. |set, c| set.add("erik", c):

friend_map_on_2nd_device.apply(friend_map_on_2nd_device.update(
"bob",
friend_map_on_2nd_device.len().derive_add_ctx(2),
|set, c| set.add("erik", c),
));

However, with GCounter instead of Orswot as the inner CRDT, this is more awkward, since the GCounter::inc function takes an actor directly, and not a context. Feels like an inconsistency. Or maybe I just missed docs somewhere, since I'm still exploring CRDTs.

My code so far, which feels wrong:

type A = &'static str;
let mut m: Map<String, GCounter<A>, A> = Map::new();
let add_ctx: AddCtx<A> = m.read_ctx().derive_add_ctx("Actor1");
m.apply(m.update(
    "Kiiya",
    add_ctx,
    |previous: &GCounter<A>, add_ctx: AddCtx<A>| {
        // return type of this closure is a `Dot<A>`.
        previous.inc(add_ctx.dot.actor) // This feels very wrong. I should be able to use the add_ctx directly here.
    }
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant