Skip to content

Support merging an ld_context and an ld_multi_context #126

@brentjanderson

Description

@brentjanderson

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions