Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Support returned values from JS events #20

Open
nesk opened this issue Mar 31, 2019 · 1 comment
Open

Support returned values from JS events #20

nesk opened this issue Mar 31, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@nesk
Copy link
Member

nesk commented Mar 31, 2019

This could be done with a Pipe class added to a JS function:

use Nesk\Rialto\Data\JsFunction;
use Nesk\Rialto\Data\Pipe;

// Create a new pipe to transfer values from JS to PHP
$pipe = new Pipe;

// Create a JS function with the pipe
$jsFunction = JsFunction::createWithBody("
    const value = { foo: 'bar' }
    customPipe.sendValue(value)
")->addPipe('customPipe', $pipe);

// Use the JS function with Rialto's implementation...

// Retrieve the transfered values through an iterator
foreach ($pipe as $value) {
    var_dump($value); // Outputs: array(1) { 'foo' => string(3) "bar" }
}

Each time the iterator of the Pipe class is called, the next value will be retrieved by communicating with the Node process. Once the value is retrieved, the Node process deletes it and will no longer be available.

@kennyth01
Copy link

hi, thanks for this, when can we get this update?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants