From 5df731a460d42593f1789f776ff923936be41b56 Mon Sep 17 00:00:00 2001 From: dsc Date: Thu, 29 Mar 2012 01:37:32 -0700 Subject: [PATCH] Cleanup. --- lib/underscore/functions.co | 92 +++++++++++++++---------------------------- lib/util/aliasdict.co | 2 +- lib/vis/presets.co | 29 ------------- 3 files changed, 33 insertions(+), 90 deletions(-) delete mode 100644 lib/vis/presets.co diff --git a/lib/underscore/functions.co b/lib/underscore/functions.co index 0dc8bf6..7327961 100644 --- a/lib/underscore/functions.co +++ b/lib/underscore/functions.co @@ -120,7 +120,7 @@ _.mixin for key in o ; # semicolon **on new line** is required by coffeescript to denote empty statement. - return key is undefined or hasOwn.call(o, key) + return key is void or hasOwn.call(o, key) ## Arrays @@ -139,7 +139,7 @@ _.mixin ## Functions -_ofArity = _.memoize( +_ofArity = _.memoize do (n, limit) -> args = ( '$'+i for i from 0 til n ).join(',') name = ( if limit then 'limited' else 'artized' ) @@ -150,95 +150,67 @@ _ofArity = _.memoize( _fn.__wraps__ = fn; return _(_fn); })" - ) -_.mixin - methodize: methodize +_.mixin do + methodize unwrap: (fn) -> (fn and _.isFunction(fn) and _.unwrap(fn.__wraps__)) or fn - partial: (fn, args...) -> - partially = -> - fn.apply this, args.concat(slice.call(arguments)) - partially.__wraps__ = fn - return _ partially + partial: (fn, ...args) -> + partially = -> + fn.apply this, args.concat slice.call(arguments) + _ partially import { __wraps__:fn } genericize: (fn) -> - g = fn.__genericized__ - return g if g + return that if fn.__genericized__ + return that if fn.__methodized__?.__wraps__ - m = fn.__methodized__ - return m.__wraps__ if m and m.__wraps__ - - g = fn.__genericized__ = (args...) -> - fn.apply args.shift(), args + fn.__genericized__ = (...args) -> + fn.apply args.shift(), args - g.__wraps__ = fn - return _ g + _ fn.__genericized__ import { __wraps__:fn } - curry: (fn, args...) -> - if not _.isFunction fn - return fn - - if fn.__curried__ - return fn.apply this, args + curry: (fn, ...args) -> + return fn unless _.isFunction fn + return fn.apply this, args if fn.__curried__ L = fn.length or _.unwrap(fn).length - if args.length >= L - return fn.apply this, args + return fn.apply this, args if args.length >= L - curried = -> + curried = -> _args = args.concat slice.call(arguments) - if _args.length >= L - return fn.apply this, _args + return fn.apply this, _args if _args.length >= L _args.unshift fn - return _.curry.apply this, _args + _.curry.apply this, _args - curried.__wraps__ = fn - curried.__curried__ = args - return _ curried + _ curried import + __wraps__ : fn + __curried__ : args flip: (fn) -> - f = fn.__flipped__ - return f if f + return that if fn.__flipped__ - f = fn.__flipped__ = \ - flipped = -> - args = arguments - hd = args[0] - args[0] = args[1] - args[1] = hd - return fn.apply this, args + fn.__flipped__ = -> + [arguments[0], arguments[1]] = [arguments[1], arguments[0]] + fn ... - f.__wraps__ = fn - return _ f + _ fn.__flipped__ import { __wraps__:fn } aritize: (fn, n) -> return fn if fn.length is n - - cache = fn.__aritized__ - if not cache - cache = fn.__aritized__ = {} - else if cache[n] - return cache[n] - - return ( cache[n] = _ofArity(n, false)(fn) ) + fn.__aritized__ or= {} + fn.__aritized__[n] or= _ofArity(n, false)(fn) limit: (fn, n) -> - cache = fn.__limited__ - if not cache - cache = fn.__limited__ = {} - else if cache[n] - return cache[n] - - return ( cache[n] = _ofArity(n, true)(fn) ) + fn.__limited__ or= {} + fn.__limited__[n] or= _ofArity(n, true)(fn) diff --git a/lib/util/aliasdict.co b/lib/util/aliasdict.co index 966c000..81cb4ef 100644 --- a/lib/util/aliasdict.co +++ b/lib/util/aliasdict.co @@ -76,7 +76,7 @@ class AliasDict def set : (key, val) -> - _.setNested @_data, key, val, true + _.setNested @_data, key, val, {+ensure} val del : (key) -> diff --git a/lib/vis/presets.co b/lib/vis/presets.co deleted file mode 100644 index 4c28d45..0000000 --- a/lib/vis/presets.co +++ /dev/null @@ -1,29 +0,0 @@ -_ = require 'kraken/underscore' -{EventEmitter} = require 'events' - -Preset = exports.Preset = Backbone.Model.extend do # {{{ - urlRoot : '/presets' - - initialize : -> - ... - - defaults : -> - {} - - -# }}} - - - -# class exports.Presets extends EventEmitter -# -# (@root) -> -# _.bindAll this, ..._.functions this -# @by_id = {root} -# -# -# fetch: (preset, cb) -> -# jQuery.ajax do -# url: "" -# - -- 1.7.0.4