Permalink
Browse files

trim the fat

  • Loading branch information...
1 parent cebb34a commit 5a9d427be5b8d63a8b8a0b765aac5f4510357b27 @vogievetsky committed Mar 7, 2012
Showing with 131 additions and 453 deletions.
  1. 0 { → d3}/d3.js
  2. 0 { → d3}/d3.time.js
  3. +60 −128 dvl.coffee
  4. +68 −163 dvl.js
  5. +1 −1 examples/misc/clock.html
  6. +1 −1 examples/misc/new.html
  7. +0 −157 sprintf.js
  8. +1 −1 tests/env.js
  9. +0 −2 todo
View
File renamed without changes.
File renamed without changes.
View
@@ -689,14 +689,6 @@ dvl.util = {
return rec
- dvl.debugFind = (name) ->
- name += '_'
- ret = []
- for id,v of variables
- if id.indexOf(name) is 0 and not isNaN(id.substr(name.length))
- ret.push v
- return ret
-
######################################################
##
## Renders the variable graph into dot
@@ -771,17 +763,17 @@ dvl.alwaysLazy = (v, fn) ->
v.setLazy(fn)
dvl.notify(v)
-dvl.zero = dvl.const(0, 'zero')
+dvl.zero = dvl.const(0).name('zero')
-dvl.null = dvl.const(null, 'null')
+dvl.null = dvl.const(null).name('null')
dvl.ident = (x) -> x
-dvl.identity = dvl.const(dvl.ident, 'identity')
+dvl.identity = dvl.const(dvl.ident).name('identity')
-dvl.acc = (c) ->
- column = dvl.wrapConstIfNeeded(c);
- acc = dvl.def(null, "acc_#{column.get()}")
+dvl.acc = (column) ->
+ column = dvl.wrapConstIfNeeded(column);
+ acc = dvl.def().name("acc")
makeAcc = ->
col = column.get();
@@ -821,25 +813,6 @@ dvl.debug = () ->
return obj
-######################################################
-##
-## A DVL object invarient maintainer
-##
-## Runs the supplied function on the data periodicaly on chage and throws the msg unless the function returns true.
-##
-##
-dvl.assert = ({data, fn, msg, allowNull}) ->
- msg or= "#{obj.id} failed its assert test"
- allowNull ?= true
-
- verifyAssert ->
- d = data.get()
- if (d isnt null or allowNull) and not fn(d)
- throw msg
-
- dvl.register({fn:verifyAssert, listen:[obj], name:'assert_fn'})
- return
-
######################################################
##
## Sets up a pipline stage that automaticaly applies the given function.
@@ -967,31 +940,6 @@ dvl.recorder = (options) ->
return array
-dvl.delay = ({ data, time, name, init }) ->
- throw 'you must provide a data' unless data
- throw 'you must provide a time' unless time
- data = dvl.wrapConstIfNeeded(data)
- time = dvl.wrapConstIfNeeded(time)
- timer = null
- out = dvl.def(init or null, name or 'delay')
-
- timeoutFn = ->
- out.set(data.get()).notify()
- timer = null
-
- dvl.register {
- listen: [data, time]
- name: name or 'timeout'
- fn: ->
- clearTimeout(timer) if timer
- timer = null
- if time.get()
- t = Math.max(0, parseInt(time.get(), 10))
- timer = setTimeout(timeoutFn, t)
- }
- return out
-
-
##-------------------------------------------------------
##
## Asynchronous ajax fetcher.
@@ -1332,76 +1280,6 @@ dvl.ajax.requester = {
}
-dvl.resizer = ({selector, out, dimension, fn}) ->
- out = dvl.wrapVarIfNeeded(out)
- dimension = dvl.wrapConstIfNeeded(dimension or 'width')
- fn = dvl.wrapConstIfNeeded(fn or dvl.identity)
-
- onResize = ->
- _dimension = dimension.get()
- _fn = fn.get()
- if _dimension in ['width', 'height'] and _fn
- if selector
- e = jQuery(selector)
- val = e[_dimension]()
- else
- val = document.body[if _dimension is 'width' then 'clientWidth' else 'clientHeight']
-
- out.update(_fn(val))
- else
- out.update(null)
-
- $(window).resize onResize
- dvl.register {
- name: 'resizer'
- listen: [dimension, fn]
- change: [out]
- fn: onResize
- }
- return out
-
-
-
-dvl.format = (string, subs) ->
- out = dvl.def(null, 'formated_out')
-
- for s in subs
- if not dvl.knows(s)
- s.fn = dvl.wrapConstIfNeeded(s.fn) if s.fn
- s.data = dvl.wrapConstIfNeeded(s.data)
-
- makeString = ->
- args = [string]
- invalid = false
- for s in subs
- if dvl.knows(s)
- v = s.get()
- if v == null
- invalid = true
- break
- args.push v
- else
- v = s.data.get()
- if v == null
- invalid = true
- break
- v = s.fn.get()(v) if s.fn
- args.push v
-
- out.set(if invalid then null else sprintf.apply(null, args))
- dvl.notify(out)
-
- list = []
- for s in subs
- if dvl.knows(s)
- list.push s
- else
- list.push s.data
-
- dvl.register({fn:makeString, listen:list, change:[out], name:'formater'})
- return out
-
-
dvl.snap = ({data, acc, value, trim, name}) ->
throw 'No data given' unless data
acc = dvl.wrapConstIfNeeded(acc or dvl.identity)
@@ -1966,6 +1844,9 @@ dvl.svg.clipPath = ({parent, x, y, width, height}) ->
return "url(##{myId})"
+
+# misc # --------------------------------------------------
+
dvl.misc = {}
dvl.misc.mouse = (element, out) ->
element = dvl.wrapConstIfNeeded(element)
@@ -1993,14 +1874,65 @@ dvl.misc.mouse = (element, out) ->
return out
+dvl.misc.delay = (data, time = 1) ->
+ data = dvl.wrapConstIfNeeded(data)
+ time = dvl.wrapConstIfNeeded(time)
+ timer = null
+ out = dvl.def()
+
+ timeoutFn = ->
+ out.set(data.get()).notify()
+ timer = null
+
+ dvl.register {
+ listen: [data, time]
+ name: name or 'timeout'
+ fn: ->
+ clearTimeout(timer) if timer
+ timer = null
+ if time.get()?
+ t = Math.max(0, time.get())
+ timer = setTimeout(timeoutFn, t)
+ }
+ return out
# HTML # --------------------------------------------------
dvl.html = {}
##-------------------------------------------------------
+## Capture the size of something in HTML
##
+dvl.html.resizer = ({selector, out, dimension, fn}) ->
+ out = dvl.wrapVarIfNeeded(out)
+ dimension = dvl.wrapConstIfNeeded(dimension or 'width')
+ fn = dvl.wrapConstIfNeeded(fn or dvl.identity)
+
+ onResize = ->
+ _dimension = dimension.get()
+ _fn = fn.get()
+ if _dimension in ['width', 'height'] and _fn
+ if selector
+ e = jQuery(selector)
+ val = e[_dimension]()
+ else
+ val = document.body[if _dimension is 'width' then 'clientWidth' else 'clientHeight']
+
+ out.update(_fn(val))
+ else
+ out.update(null)
+
+ $(window).resize onResize
+ dvl.register {
+ name: 'resizer'
+ listen: [dimension, fn]
+ change: [out]
+ fn: onResize
+ }
+ return out
+
+##-------------------------------------------------------
## Output to an HTML attribute
##
dvl.html.out = ({selector, data, fn, format, invalid, hideInvalid, attr, style, text}) ->
Oops, something went wrong.

0 comments on commit 5a9d427

Please sign in to comment.