   componentDidMount: -> @callModules @props.children.props
   componentWillReceiveProps: (props) -> @callModules props.children.props
   callModules: (props) ->
-    for own module, args of props
-      if (Array.isArray args) and (typeof jQuery.fn[module] is 'function') and (module in Aui.module)
-        $element = jQuery React.findDOMNode @
-        console.log $element[0]
-        ($element)[module] args...
+    $element = jQuery React.findDOMNode @
+    moduleId = $element.attr 'data-reactid'
+    if moduleId isnt @moduleId
+      console.log 'moduleId isnt @moduleId', moduleId, @moduleId
+      delete moduleCache[@moduleId]
+    @moduleId = moduleId
+    moduleCache[@moduleId] or= {}
+    for module, options in @props.modules
+      cacheOptions = JSON.stringify options
+      if moduleCache[@moduleId][module] isnt cacheOptions
+        moduleCache[@moduleId][module] = cacheOptions
+        ($element)[module] @props.children.props[module]...
     return
-
+  componentWillUnmount: ->
+    delete moduleCache[@moduleId]
 window?.Aui = Aui
 module?.exports = Aui

    for own key, value of Aui.defaults
      @[key] = if options[key]? then options[key] else value

## element `Aui.classify(ReactElement, {...props}, { boolean modules })`
# finds all the props that === true or are on the `Aui.modules` list,
# and merging them with the className prop.
# `Aui.classify(<div ui grid><div column>content</div></div>)`
# returns `<div ui grid className="ui grid"><div column className="column">content</div></div>`
Aui.classify = (parent, options) ->
  options = AuiOptions options
  classify = (element) ->
    return element unless React.isValidElement element
    classNames = {}

unless jQuery? then console.warn "Aui: window.jQuery not found, Modules and Semantic-UI will be disabled."
unless jQuery?.site?.settings?.modules? then console.warn 'Aui: No Semantic-UI window.jQuery.site.settings.modules found, Semantic will be disabled.'

## mixin Aui.Mixin
# Aui class is the main wrapper class
# it recursively goes through all it's children,
# finding props that === true or are on the `Aui.modules` list,
# and merges them into the className of each element.
AuiMixin =
  componentWillMount: ->
    render = @render
    @render = ->
      element = render?.apply? @, arguments
      if React.isValidElement element
        Aui.classify element, @props
      else
        Aui.classify (Aui.warning 'Aui.Mixin: Child is not a React.isValidElement', element), @props

## class <Aui/>
# A tag that applies the Aui.Mixin
Aui = React.createClass
  mixins: [AuiMixin]
  render: -> @props.children
Aui.Aui = Aui
Aui.Mixin = Aui.AuiMixin = AuiMixin

## function Aui.warning (string, element)
# console.warn a warning message
# returns the element wrapped in a warning span
Aui.warning = (message, element) ->
  console.warn message, element
  React.DOM.span { 'data-warning': message }, element

## object Aui.defaults
# The default options Aui uses when no options or props are passed in.
