Skip to content

Port.send a Maybe Value #81

Open
Open
@nikoskalogridis

Description

@nikoskalogridis

I am sending a Maybe Value on a port in order to clear the localstorage key when it receives a null value (through sending a Nothing on logout). Trying to do the same in the following code:

encode : Cred -> Decode.Value
encode (Cred user tokenInfo) =
    Encode.object
        [ ( "user", User.encode user )
        , ( "token", tokenInfoEncoder tokenInfo )
        ]

storeCredWith : Cred -> Cmd msg
storeCredWith cred =
    storeCache (Just (encode cred))

simulateStoreCredWith : Cred -> ProgramTest.SimulatedEffect msg
simulateStoreCredWith cred =
    SimulatedEffect.Ports.send "storeCache" (Just (encode cred))

logout : Cmd msg
logout =
    storeCache Nothing

port storeCache : Maybe Value -> Cmd msg

fails with:

TYPE MISMATCH - The 2nd argument to `send` is not what I expect:

SimulatedEffect.Ports.send "storeCache" (Just (encode cred))
                                        #^^^^^^^^^^^^^^^^^#
This `Just` call produces:
    #Maybe Value#
But `send` needs the 2nd argument to be:
    #Encode.Value#

is there a way to simulate this (ie Port.send a Maybe Value) ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionThis is a question about the package, and not actually an "issue".

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions