erlang-server-sdk icon indicating copy to clipboard operation
erlang-server-sdk copied to clipboard

Support merging an ld_context and an ld_multi_context

Open brentjanderson opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

I'd like to be able to use :ldclient_context.new_multi_from/1 with a mixed list of :ldclient_context.context() and :ldclient_context.multi_context().

Presently, you end up with a multi context that looks something like this:

contexts = [
  :ldclient_context.new_from_map(%{kind: "some-context", key: "some-context-key"}),
  :ldclient_context.new_from_map(%{kind: "user", key: "some-user-key"}),
]

multi_context = :ldclient_context.new_multi_from(contexts)

more_contexts = [
  multi_context,
  :ldclient_context.new_from_map(%{kind: "another-context", key: "foobar"})
]

bad_context = :ldclient_context.new_multi_from(more_contexts)

# I would hope that bad_context would look something like this:

%{
  :kind => "multi",
  "some-context" => %{key: "some-account-key"},
  "another-context" => %{key: "foobar"},
  "user" => %{key: "some-user-key"}
} == bad_context # This equality check fails

# Unfortunately, it looks like this:

%{
  :kind => "multi",
  "multi" => %{
    "some-context" => %{key: "some-context"},key
    "user" => %{key: "some-user-key"}
  },
  "another-context" => %{key: "foobar"}
} == bad_context

Describe the solution you'd like I'd like to be able to combine a mixed list of LD Contexts & Multi contexts into a single, well-formatted LD multi context.

Describe alternatives you've considered I have a workaround that handles building a list of LD Contexts and then merging them all at once, but running at the library level would be more convenient.

Additional context N/A

brentjanderson avatar May 15 '24 02:05 brentjanderson

Hi @brentjanderson, that is a reasonable request. We'll consider how to handle this and get back to you.

Filed internally as 244385.

cwaldren-ld avatar May 15 '24 17:05 cwaldren-ld