Giter Site home page Giter Site logo

aura.signal's People

Contributors

harikt avatar koriym avatar omniton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aura.signal's Issues

Fatal error: Call to a member function getLast() on a non-object

Was playing with Aura.Signal

Error :

Fatal error: Call to a member function getLast() on a non-object

Fix : return results collection object for the send() and process() not returning anything .

Another Qn is :

In constructor itself we are cloning the result collection $this->results = clone $this->result_collection; , then why we need it in send() method again ?

// In Aura/Signal/Manager

public function send($origin, $signal)
{
    // clone a new result collection
    $this->results = clone $this->result_collection;

    // get the arguments to be passed to the handler
    $args = func_get_args();
    array_shift($args);
    array_shift($args);

    // now process the signal through the handlers
    $this->process($origin, $signal, $args);
    //return the result collection .
    return $this->results ;
}

Below is code that I was playing

<?php
use Aura\Signal\Manager as SignalManager;

class Example
{
    protected $signal;

    public function __construct(SignalManager $signal)
    {
        $this->signal = $signal;
    }

    public function doSomething($text)
    {
        echo __METHOD__ . "<br/>";
        $results = $this->signal->send($this, 'example_signal', $text);
        /*
        $results = $this->signal->getResults();
        // go through each result ...
        foreach ($results as $result) {
            // ... and echo the value returned by the Handler callback
            //echo "<br /> The object that sent the signal. " . $result->origin;
            echo "<br /> The sender expected by the Handler. " . $result->sender;
            echo "<br /> The signal that was sent by the origin. " . $result->signal;
            echo "<br /> The value returned by the Handler callback. " . $result->value;
        }
         * 
         */
        $result = $results->getLast();
        echo "<br /> The signal that was sent by the origin. " . $result->signal;
        echo "<br /> The value returned by the Handler callback. " . $result->value;
    }
}

class ExampleOther
{
    protected $signal;

    public function __construct(SignalManager $signal)
    {
        $this->signal = $signal;
    }

    public function doSomethingElse($text)
    {
        echo __METHOD__ . "<br/>";
        $this->signal->send($this, 'example_signal', $text);
    }
}

$signal = require_once __DIR__ . '/Aura.Signal/scripts/instance.php';
$signal->handler(
    '*',
    'example_signal',
    function ($arg ) { 
        echo " example_signal Called " . $arg; 
    }
);

$closure = function() { 
    echo "Before all others. <br />"; 
    return " From Signal 1000";     
};
$signal->handler('Example', 'example_signal', $closure, 1000);

// add a closure at position 9000, which means it will be processed
// after all handlers at the default position 5000.
$closure = function() { 
    echo "<br /> After all others. <br />"; 
    return " From signal closure of value 6000";
};
$signal->handler('Example', 'example_signal', $closure, 6000);

$eg1 = new Example( $signal );
$eg1->doSomething('Hello World');

//$eg2 = new ExampleOther( $signal );
//$eg2->doSomethingElse('Hello World');

Qn : getResults() on Manager

Hi Paul,

I was wondering whether it is good to keep the results of all the events fired.

For eg : In a method there can be many events triggering. In that case the result of signal is not obtained, or is replaced. What do you suggest for things like that ?

I wonder whether getResults($signal_name) should have a functionality to look and give back the results.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.