Skip to content

Commit

Permalink
Rename update to trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin de Graaf committed Aug 13, 2018
1 parent dde4e8b commit 8733869
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Parable Event

## 0.2.0

_Changes:_
- Rename `update()` to `trigger()`.
- Update README to show the correct API.

## 0.1.0

_Changes:_
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ composer require parable-php/event
## Usage

Events are very simple. You add listeners to events (`string` values) and then trigger an update with those events. You
can pass payloads into the update calls, which will get passed to all relevant listeners.
can pass payloads into the `trigger` calls, which will get passed to all relevant listeners.

```php
use \Parable\Event\EventManager;
Expand All @@ -42,7 +42,7 @@ The above example handily shows how to make scalar values modifiable by defining
reference. Passing objects is generally advisable, but sometimes it's the in-place alteration of string values you
need.

It's also possible to have a listener trigger on every single event update.
It's also possible to have a listener trigger on every single event.

```php
$eventManager->listenAll(function (string $event, $payload) {
Expand All @@ -57,8 +57,8 @@ events.
## API

- `listen(string $event, callable $$listener): void` - add listener to an event
- `listenAll(string $event): void` - add listener for all events
- `update(string $event): void` - trigger an update for an event
- `listenAll(callable $$listener): void` - add listener for all events
- `trigger(string $event, $payload): void` - trigger an update for an event

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion src/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function listenAll(callable $listener): void
*
* @param null|mixed $payload
*/
public function update(string $event, &$payload = null)
public function trigger(string $event, &$payload = null)
{
if ($event === self::GLOBAL_EVENT) {
throw new Exception('Cannot specifically trigger global event.');
Expand Down
12 changes: 6 additions & 6 deletions tests/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testListenToEventAndUpdate()

$payload = 'payload';

$this->eventManager->update('test_event', $payload);
$this->eventManager->trigger('test_event', $payload);

self::assertSame('payload-suffixed', $payload);
}
Expand All @@ -39,7 +39,7 @@ public function testMultipleEvents()

$payload = 'payload';

$this->eventManager->update('test_event', $payload);
$this->eventManager->trigger('test_event', $payload);

self::assertSame('payload-suffixed-twice!', $payload);
}
Expand All @@ -55,7 +55,7 @@ public function testSameEventMultipleTimesGetsCalledOnce()

$payload = 'payload';

$this->eventManager->update('test_event', $payload);
$this->eventManager->trigger('test_event', $payload);

self::assertSame('payload-suffixed', $payload);
}
Expand All @@ -68,8 +68,8 @@ public function testGlobalListeners()

$payload = 'payload';

$this->eventManager->update('once update', $payload);
$this->eventManager->update('twice update', $payload);
$this->eventManager->trigger('once update', $payload);
$this->eventManager->trigger('twice update', $payload);

self::assertSame('payload-suffixed-suffixed', $payload);
}
Expand All @@ -79,6 +79,6 @@ public function testCannotTriggerGlobalEvent()
self::expectException(Exception::class);
self::expectExceptionMessage('Cannot specifically trigger global event.');

$this->eventManager->update('*');
$this->eventManager->trigger('*');
}
}

0 comments on commit 8733869

Please sign in to comment.