Skip to content

Instantly share code, notes, and snippets.

@island205
Created February 3, 2012 07:57
Show Gist options
  • Save island205/1728849 to your computer and use it in GitHub Desktop.
Save island205/1728849 to your computer and use it in GitHub Desktop.
###
AOP开始
###
DO =
objs: {}
before: (fn, obj, sFn, c) ->
after: (fn, obj, sFn, c) ->
_inject: (when_, fn, obj, sFn) ->
detach: (handle) ->
Y.Do = DO
DO.Method = (obj, sFn) ->
DO.Method::register = (sid, fn, when_) ->
DO.Method::_delete = (sid) ->
DO.Method::exec = ->
DO.AlterArgs = (msg, newArgs) ->
DO.AlterReturn = (msg, newRetVal) ->
DO.Halt = (msg, retVal) ->
DO.Prevent = (msg) ->
DO.Error = DO.Halt
Y.CustomEvent = (type, o) ->
@id = Y.stamp(this)
@subscribers = {}
@afters = {}
###
AOP结束
###
###
自定义事件 开始
###
Y.CustomEvent:: =
constructor: Y.CustomEvent
hasSubs: (when_) ->
monitor: (what) ->
getSubs: ->
_on: (fn, context, args, when_) ->
on: (fn, context) ->
after: (fn, context) ->
detach: (fn, context) ->
_notify: (s, args, ef) ->
fire: ->
fireSimple: (args) ->
fireComplex: (args) ->
_procSubs: (subs, args, ef) ->
detachAll: ->
_delete: (s) ->
###
自定义事件结束
###
###
订阅者 开始
###
Y.Subscriber = (fn, context, args) ->
Y.Subscriber:: =
constructor: Y.Subscriber
_notify: (c, args, ce) ->
notify: (args, ce) ->
contains: (fn, context) ->
###
订阅者 结束
###
###
自定义事件句柄 开始
###
Y.EventHandle = (evt, sub) ->
Y.EventHandle:: =
batch: (f, c) ->
detach: ->
monitor: (what) ->
###
自定义事件句柄 结束
###
###
事件宿主 开始
###
ET = (opts) ->
ET:: =
constructor: ET
once: ->
onceAfter: ->
on: (type, fn, context) ->
subscribe: ->
detach: (type, fn, context) ->
unsubscribe: ->
detachAll: (type) ->
unsubscribeAll: ->
publish: (type, opts) ->
_monitor: (what, type, o) ->
fire: (type) ->
getSibling: (type, ce) ->
getEvent: (type, prefixed) ->
after: (type, fn) ->
before: ->
Y.EventTarget = ET
###
事件宿主 结束
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment