Sha256: 605e76aab258177c2a24e46bf6711cf101de893cb60eb69c08608e265e7b6ef4

Contents?: true

Size: 928 Bytes

Versions: 1

Compression:

Stored size: 928 Bytes

Contents

Joosy.Modules.Events =
  wait: (events, callback) ->
    events = events.split /\s+/

    @__oneShotEvents ||= []
    @__oneShotEvents.push [events, callback]

  bind: (events, callback) ->
    events = events.split /\s+/

    @__boundEvents ||= []
    @__boundEvents.push [events, callback]

  unbind: (target) ->
    for [events, callback], index in @__boundEvents
      if callback == target
        @__boundEvents.splice index, 1
        return

  trigger: (event) ->
    Joosy.Modules.Log.debugAs @, "Event #{event} triggered"
    if @__oneShotEvents
      for [events, callback], index in @__oneShotEvents
        position = events.indexOf event
        if position >= 0
          events.splice position, 1

        if events.length == 0
          @__oneShotEvents.splice index, 1

          callback()

    if @__boundEvents
      for [events, callback] in @__boundEvents
        if events.has event
          callback()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
joosy-0.1.0.RC2 app/assets/javascripts/joosy/core/modules/events.js.coffee