Adds a rule to handle user event, such as click, subscribe

@param string $name
@param Closure|string $key
@param Closure $fn
@return $this
966639
public function on($name, $key, Closure $fn = null)
    {
        $name = strtolower($name);
        if ($key instanceof Closure) {
            $this->rules['event'][$name][''] = $key;
        } else {
            $this->rules['event'][$name][$key] = $fn;
        }
        return $this;
    }
988935
public function addAction($key, $name, $href = null, array $params = null)
	{
		$this->addActionCheck($key);

		$href = $href ?: $key;

		if ($params === null) {
			$params = [$this->primary_key];
		}

		return $this->actions[$key] = new Column\Action($this, $href, $name, $params);
	}
279715
public function addListener($name, callable $callback) {
        if(!array_key_exists($name, $this->registered_events)) {
            $this->registered_events[$name] = [];
        }

        $this->registered_events[$name][] = $callback;
    }
594138
protected function set($name, \Closure $extension)
    {
        $this->getExtensions()->set($name, $extension);
        
        return $this;
    }
871557
public function withEntryFromClosure(string $key, \Closure $closure): self
    {
        $this->bindings[$key] = $closure;
        return $this;
    }
893663
protected function _closure($data, $name)
    {
        $isExpanded = $this->_isExpandedLevel();

        ?>
        <li class="jbchild">
            <div
                class="jbelement<?php echo count((array)$data) > 0 ? ' jbexpand' : ''; ?> <?= $isExpanded ? 'jbopened' : ''; ?>"
                <?php if (count((array)$data) > 0) { ?> onClick="jbdump.toggle(this);"<?php } ?>>
                <span class="jbname"><?php echo $name; ?></span> (<span class="jbtype jbtype-closure">Closure</span>)
                <span class="jbvalue"><?php echo get_class($data); ?></span>
            </div>
            <?php $this->_vars($this->_getFunction($data), $isExpanded); ?>
        </li>
    <?php
    }
506736
public function subscribe($key, $handler, $params = array())
    {
        Event::subscribe($key, $handler, $params);

        return $this;
    }
374658
public function onRegister($name, Closure $callback)
    {
        $priority                  = $this->getPluginPriority($name);
        $this->registerCallbacks[] = compact('name', 'priority', 'callback');
    }
706133
public function existsOrSet($key, \Closure $fn) : bool
    {
        $key = $this->getCompositeKey($key);
        if (!ArrayHelper::key_exists($this->storage, $key)) {
            if ($fn instanceof \Closure) {
                $value = $fn($this);
                $this->set($key, $value);
            }
            return false;
        }
        return true;
    }
1188938
public function triggerAndCount($name, ...$args)
    {
        if ($this->addThisToEvents) {
            array_unshift($args, $this);
        }
        $cnt = 0;
        if (isset($this->eventHandlers[$name])) {
            $this->lastEventName = $name;
            foreach ($this->eventHandlers[$name] as $cb) {
                if ($cb(...$args) !== 0) {
                    ++$cnt;
                }
            }
        }
        return $cnt;
    }
640462
public function addButtonSubmit(string $name) : Element\Button\Submit
    {
        $button = new Element\Button\Submit($this, $name);
        $this->addComponent($name, $button);

        return $button;
    }
12370
public function add(string $name, callable $callback): self
    {
        if ($this->exists($name)) {
            throw new LogicException(
                'The helper function name "' . $name . '" is already registered.'
            );
        }

        $this->helpers[$name] = $callback;

        return $this;
    }
862516
public static function extend(BladeCompiler $blade, $name, $closure)
    {
        // For 5.0 after
        if (is_callable([$blade, 'directive'])) {
            $blade->directive($name, $closure);

            return;
        }

        // For 4.x before
        $blade->extend(
            function ($view, BladeCompiler $compiler) use ($name, $closure) {
                $pattern = $compiler->createMatcher($name);

                return preg_replace_callback(
                    $pattern,
                    function ($matches) use ($closure) {
                        if (empty($matches[2])) {
                            return $matches[0];
                        }

                        return $matches[1] . $closure($matches[2]);
                    },
                    $view
                );
            }
        );

        return;
    }
1306732
public function bind($name, \Closure $type)
    {
        $name = '\\'.ltrim($name, '\\');
        $this->bindings[$name] = $type;
    }
1329765
public function set(string $name, Closure $definition)
    {
        if ($this->has($name)) {
            throw new DefinitionAlreadyExistsException(
                "Breadcrumbs have already been defined for route [{$name}]."
            );
        }

        $this->definitions[$name] = $definition;
    }
95916
public function javascript($name, Closure $callback = null)
    {
        return $this->add($name, function($asset) use ($callback)
        {
            $asset->setGroup('javascripts');

            is_callable($callback) and call_user_func($callback, $asset);
        });
    }
1370114
public function modify($name, Closure $callback)
    {
        $menu = collect($this->menus)->filter(function ($menu) use ($name) {
            return $menu->getName() == $name;
        })->first();

        $callback($menu);
    }