Skip to content

Commit

Permalink
Add support context sensitive events
Browse files Browse the repository at this point in the history
Add support for optionally passing a context with events on the event
bus. This makes it possible for `Area`, `SingleInput` and
`MultipleInput` components to address events to a particular instance
of a Droplet component.
  • Loading branch information
Simen Heggestøyl committed Apr 20, 2016
1 parent 79c603a commit 5e80bee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ Use as singular or in block form — `Droplet.Area` will create a `div` with
{{x-droplet-area}}
```

If you need have several droppable areas on the same page handling hooks independently, a context must be supplied:

```html
{{x-droplet-area ctx=this}}
```

### Image Preview

```javascript
Expand All @@ -161,6 +167,12 @@ Use in its singular form – can use either `Droplet.MultipleInput` or `Drop
{{x-droplet-input}}
```

If you need have several input fields on the same page handling hooks independently, a context must be supplied:

```html
{{x-droplet-input ctx=this}}
```

Example
-------------

Expand Down
12 changes: 8 additions & 4 deletions components/Droplet.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@
$Ember.merge(options, this.get('options'));
set(this, 'options', options);

this.DropletEventBus && this.DropletEventBus.subscribe(EVENT_NAME, this, (...files) => {
this.send('prepareFiles', ...files);
this.DropletEventBus && this.DropletEventBus.subscribe(EVENT_NAME, this, (ctx, ...files) => {
if (!ctx || ctx === this) {
this.send('prepareFiles', ...files);
}
});

this._super();
Expand Down Expand Up @@ -744,7 +746,8 @@
* @return {Model[]}
*/
handleFiles(models) {
this.DropletEventBus && this.DropletEventBus.publish(EVENT_NAME, ...fromArray(models));
this.DropletEventBus && this.DropletEventBus.publish(
EVENT_NAME, this.get('ctx'), ...fromArray(models));
return models;
},

Expand Down Expand Up @@ -894,7 +897,8 @@
* @return {void}
*/
handleFiles(models) {
this.DropletEventBus && this.DropletEventBus.publish(EVENT_NAME, ...fromArray(models));
this.DropletEventBus && this.DropletEventBus.publish(
EVENT_NAME, this.get('ctx'), ...fromArray(models));
}

});
Expand Down

0 comments on commit 5e80bee

Please sign in to comment.