Skip to content

Commit

Permalink
Unified order of components and mixins.
Browse files Browse the repository at this point in the history
Fixes #4 and fixes #11.
  • Loading branch information
mitar committed Apr 7, 2015
1 parent 668e169 commit ef7f635
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Returned values from event handlers are ignored. To control how events are propa
methods like [`stopPropagation`](https://api.jquery.com/event.stopPropagation/) and
[`stopImmediatePropagation`](https://api.jquery.com/event.stopImmediatePropagation/).

When [mixins](#mixins-1) provide event handlers, they are attached in order of mixins, with the component last.
When [mixins](#mixins-1) provide event handlers, they are attached in order of mixins, with the component first.

*For more information about event maps, event handling, and `event` object, see [Blaze documentation](http://docs.meteor.com/#/full/eventmaps)
and [jQuery documentation](https://api.jquery.com/category/events/event-object/).*
Expand Down Expand Up @@ -518,7 +518,7 @@ class ButtonComponent extends BlazeComponent
You can now use [`postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) to send messages
like `{color: "Blue"}` which would reactively change the label of the button.

When [mixins](#mixins-1) provide `onCreated` method, the default implementation calls them in order.
When [mixins](#mixins-1) provide `onCreated` method, the default component implementation calls them in order.

<a name="reference_instance_onRendered"></a>
```coffee
Expand All @@ -534,7 +534,7 @@ This is the place where you can initialize 3rd party libraries to work with the
mind that interactions of a 3rd party library with Blaze controlled content might bring unintentional consequences
so consider reimplementing the 3rd party library as a Blaze Component instead.

When [mixins](#mixins-1) provide `onRendered` method, the default implementation calls them in order.
When [mixins](#mixins-1) provide `onRendered` method, the default component implementation calls them in order.

<a name="reference_instance_onDestroyed"></a>
```coffee
Expand All @@ -547,7 +547,7 @@ with a re-rendering.
Here you can clean up or undo any external effects of [`onCreated`](#user-content-reference_instance_onCreated)
or [`onRendered`](#user-content-reference_instance_onRendered) methods. See the example above.

When [mixins](#mixins-1) provide `onDestroyed` method, the default implementation calls them in order.
When [mixins](#mixins-1) provide `onDestroyed` method, the default component implementation calls them in order.

#### Utilities ####

Expand Down Expand Up @@ -591,8 +591,8 @@ implementation is that if `node` has not yet been inserted, it simply inserts th
You can extend this method if you want to insert the new DOM element in a different way, for example, by animating
it. Make sure you do insert it correctly because Blaze will expect it to be there afterwards.

When [mixins](#mixins-1) provide `insertDOMElement` method, the default implementation calls them in order. Make
sure to always verify the state of the DOM before proceeding with mixin's logic. Some other mixin might already
When [mixins](#mixins-1) provide `insertDOMElement` method, the default componnet implementation calls them in order.
Make sure to always verify the state of the DOM before proceeding with mixin's logic. Some other mixin might already
inserted the DOM element.

<a name="reference_instance_moveDOMElement"></a>
Expand All @@ -607,8 +607,8 @@ DOM element, or as the last element if `before` is `null`.
You can extend this method if you want to move the DOM element in a different way, for example, by animating
it. Make sure you do move it correctly because Blaze will expect it to be there afterwards.

When [mixins](#mixins-1) provide `moveDOMElement` method, the default implementation calls them in order. Make
sure to always verify the state of the DOM before proceeding with mixin's logic. Some other mixin might already
When [mixins](#mixins-1) provide `moveDOMElement` method, the default component implementation calls them in order.
Make sure to always verify the state of the DOM before proceeding with mixin's logic. Some other mixin might already
moved the DOM element.

<a name="reference_instance_removeDOMElement"></a>
Expand All @@ -622,8 +622,8 @@ if `node` has not yet been removed, it simply removes the `node` DOM element.
You can extend this method if you want to remove the DOM element in a different way, for example, by animating
it. Make sure you do remove it correctly because Blaze will expect it to be removed afterwards.

When [mixins](#mixins-1) provide `removeDOMElement` method, the default implementation calls them in order. Make
sure to always verify the state of the DOM before proceeding with mixin's logic. Some other mixin might already
When [mixins](#mixins-1) provide `removeDOMElement` method, the default component implementation calls them in order.
Make sure to always verify the state of the DOM before proceeding with mixin's logic. Some other mixin might already
removed the DOM element.

#### Mixins ####
Expand Down
14 changes: 7 additions & 7 deletions lib.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ Blaze._getTemplateHelper = (template, name, templateInstance) ->

# Component.
if component
# We first search on the component.
if name of component
return wrapHelper bindComponent(component, component[name]), templateInstance

# And then continue with mixins.
if mixin = component.getMixinWith null, name
return wrapHelper bindComponent(mixin, mixin[name]), templateInstance

Expand Down Expand Up @@ -319,6 +321,7 @@ class BlazeComponent extends BaseComponent
else
found = false

# TODO: Implement with a map between mixin -> position, so that we do not have to seek to find a mixin.
for mixin in @_mixins
return mixin if found and propertyName of mixin

Expand Down Expand Up @@ -430,16 +433,13 @@ class BlazeComponent extends BaseComponent
# Attach events the first time template instance renders.
return unless @view.renderCount is 1

assert @component._mixins
# We first add event handlers from the component, then mixins.
addEvents @view, @component

# We manually go over _mixins instead of using getMixin because we also need
# the mixin itself so that we can bind events correctly.
for mixin in @component._mixins when 'events' of mixin
mixin = null
while mixin = @component.getMixinWith mixin, 'events'
addEvents @view, mixin

# We first add event handlers from mixins, then the component.
addEvents @view, @component

@component = component
@component.templateInstance = @
@component.onCreated()
Expand Down

0 comments on commit ef7f635

Please sign in to comment.