Encapsulating communication of nested component ports in Elm?

I have a reusable Elm component that is designed to be reused in multiple places (in the style of a tutorial . I have a Javascript function that I would like to use for port communications, but creating a port subscription forces each β€œinstance” of my component to receive every message that I send back from Javascript.

Ideally, parent components do not need to perform filtering outside the normal Cmd.map ChildMsg . The simplest solution I can come up with is to add an identifier to each child model and filter in the child’s own update function, but this is a bit unsuccessful and requires me to create an identifier if it does not already exist.

As an example of my ideal result, the Http modules allow you to return the task and get the result back, addressed only to the specific instance that requested it. I managed to emulate this behavior using the simplified Native module: https://github.com/tgecho/elm-custom-task-example

 function getNumber(number) { return _elm_lang$core$Native_Scheduler.nativeBinding(function(callback) { return callback(_elm_lang$core$Native_Scheduler.succeed(number)); }); } 

Then my component can call this function, returning the Task.perform NaN Increment (Number.getNumber 1) task and getting the result back as an Increment message.

What am I missing? Is there a way to encapsulate a port connection without writing Native code or adding identifiers to everything?

+7
javascript elm
source share

No one has answered this question yet.

See related questions:

770
How can I access and process nested objects, arrays or JSON?
22
Run two teams at the same time in Elm
5
How to create a task with messages that require a payload in Elm?
4
communication between components in Elm
4
sending a signal from a subcomponent in elm
2
Elm share a subscription?
2
Elm effects mapped to a nested component
one
Best sample for calling AWS API from Elm SPA?
one
One-way javascript message
0
Elm 0.18: How to send messages from Sub.map based on their contents?

All Articles