Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 5 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 24 additions and 18 deletions.
  1. +21 −18 bling.coffee
  2. +3 −0 tests/bling.coffee
View
39 bling.coffee
@@ -12,6 +12,8 @@
# ---------
# We need a few things to get started.
+# We need a few things to get started:
+
# A safe logger to use for `$.log()`.
log = (a...) ->
try return console.log.apply console, a
@@ -233,7 +235,7 @@ class Bling
extend @::, plugin
# Finally, add root-level wrappers for anything that doesn't
# have one already.
- ( @[key] or= (a...) => (@::[key].apply $(a[0]), a[1...]) ) for key of plugin # and gets a default global implementation
+ ( @[key] or= (a...) => (@::[key].apply $(a[0]), a[1...]) ) for key of plugin
if opts.provides? then @provide opts.provides
catch error
log "failed to load plugin: #{this.name} '#{error.message}'"
@@ -441,14 +443,14 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
next = (a) -> -> a.shift()() if a.length
add: (f, n) ->
f.order = n + $.now
- for i in [0..@length]
+ for i in [0..@length] by 1
if i is @length or @[i].order > f.order
@splice i,0,f
break
setTimeout next(@), n
@
cancel: (f) ->
- for i in [0...@length]
+ for i in [0...@length] by 1
if @[i] == f
@splice i, 1
break
@@ -462,7 +464,6 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
(n, f) ->
if $.is("function",f) then timeoutQueue.add(f, n)
cancel: -> timeoutQueue.cancel(f)
-
)()
# Continue with _f_ after _n_ milliseconds.
@@ -562,7 +563,7 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
# Replace any false-ish items in _this_ with _x_.
# > `$("<a>").select('parentNode').or(document)`
- or: (x) -> @[i] or= x for i in [0...@length]; @
+ or: (x) -> @[i] or= x for i in [0...@length] by 1; @
# Assign the value _v_ to property _b_ on every
# item in _this_.
@@ -599,12 +600,12 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
# Get a new set with only the first _n_ items from _this_.
take: (n = 1) ->
end = Math.min n, @length
- $( @[i] for i in [0...end] )
+ $( @[i] for i in [0...end] by 1 )
# Get a new set with every item except the first _n_ items.
skip: (n = 0) ->
start = Math.max 0, n|0
- $( @[i] for i in [start...@length] )
+ $( @[i] for i in [start...@length] by 1 )
# Get the first item(s).
first: (n = 1) -> if n is 1 then @[0] else @take(n)
@@ -616,10 +617,11 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
slice: (start=0, end=@length) ->
start = index start, @
end = index end, @
- $( @[i] for i in [start...end] )
+ $( @[i] for i in [start...end] by 1 )
# Append the items in _b_ into _this_. Modifies _this_ in-place.
extend: (b) -> @.push(i) for i in b; @
+
# Appends a single item to _this_; unlike a native Array, it
# returns a reference to _this_ for chaining.
push: (b) -> Array::push.call(@, b); @
@@ -658,10 +660,11 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
weave: (b) ->
c = $()
# First spread out _this_, from back to front.
- n = @length-1
- (c[(i*2)+1] = @[i]) for i in [n..0]
+ for i in [@length-1..0] by -1
+ c[(i*2)+1] = @[i]
# Then interleave items from _b_, from front to back
- (c[i*2] = b[i]) for i in [0...b.length]
+ for i in [0...b.length] by 1
+ c[i*2] = b[i]
c
# Notes about `weave`:
# * the items of b come first.
@@ -718,9 +721,9 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
step *= -1 if end < start and step > 0 # force step to have the same sign as start->end
$( (start + (i*step)) for i in [0...Math.ceil( (end - start) / step )] )
# Get an array of zeros.
- zeros: (n) -> $( 0 for i in [0...n] )
+ zeros: (n) -> $( 0 for i in [0...n] by 1 )
# Get an array of ones.
- ones: (n) -> $( 1 for i in [0...n] )
+ ones: (n) -> $( 1 for i in [0...n] by 1)
# Convert everything to a float.
floats: -> @map parseFloat
# Convert everything to an int.
@@ -746,7 +749,7 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
# Add this to d, get a new set.
add: (d) -> switch $.type(d)
when "number" then @map -> d + @
- when "bling","array" then $( @[i]+d[i] for i in [0...Math.min(@length,d.length)-1] )
+ when "bling","array" then $( @[i]+d[i] for i in [0...Math.min(@length,d.length)-1] by 1 )
# Get a new set with same direction, but magnitude equal to 1.
normalize: -> @scale(1/@magnitude())
@@ -805,7 +808,7 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
# Convert a _camelCase_ name to a _dash-name_.
dashize: (name) ->
ret = ""
- for i in [0...(name?.length|0)]
+ for i in [0...(name?.length|0)] by 1
c = name.charCodeAt i
# For each uppercase character,
if 91 > c > 64
@@ -919,7 +922,7 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
$.type.extend
unknown: { trace: $.identity }
object: { trace: (o, label, tracer) -> (o[k] = $.trace(o[k], "#{label}.#{k}", tracer) for k in Object.keys(o)); o }
- array: { trace: (o, label, tracer) -> (o[i] = $.trace(o[i], "#{label}[#{i}]", tracer) for i in [0...o.length]); o }
+ array: { trace: (o, label, tracer) -> (o[i] = $.trace(o[i], "#{label}[#{i}]", tracer) for i in [0...o.length] by 1); o }
function:
trace: (f, label, tracer) ->
r = (a...) ->
@@ -1482,7 +1485,7 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
if @style.display is not "none"
@_display = @syle.display
@style.display = "none"
- .trigger "hide"
+ .trigger("hide")
.delay updateDelay, callback
show: (callback) -> # .show() - show each node
@@ -1490,7 +1493,7 @@ Bling.prototype = [] # similar to `class Bling extends (new Array)`,
if @style
@style.display = @_display
delete @_display
- .trigger "show"
+ .trigger("show")
.delay updateDelay, callback
toggle: (callback) -> # .toggle() - show each hidden node, hide each visible one
View
3 tests/bling.coffee
@@ -200,6 +200,7 @@ testGroup("HTML",
assertEqual( $.HTML.stringify($.HTML.parse(h)), h)
select_childNodes: -> assertEqual( $("<div><a></a><b></b><c></c></div>").select("childNodes").flatten().map($.type).toString(), "$([node, node, node])" )
child: -> i = 0; d = $("<div><a></a><b></b><c></c></div>"); assertEqual( d.select('childNodes').flatten().map( () -> d.child(i++) ).toString(), "$([$([<a/>]), $([<b/>]), $([<c/>])])")
+ child2: -> assertEqual($("tr").child(0).select('nodeName').toString(), "$([TD, TD, TD, TD])")
textData: ->
d = $("<div>&nbsp;</div>")
assertEqual( d.toString(), "$([<div>&nbsp;</div>])" )
@@ -270,6 +271,8 @@ testGroup("HTML",
value1: -> assertEqual($("<input type='text' value='foo'/>").val().toString(), "$([foo])")
value2: -> assertEqual($("<input />").val().toString(), "$([])")
value3: -> assertEqual($("<input type='checkbox' checked />").val().toString(), "$([on])")
+ parents: -> assertEqual($("td.d").parents().first().select('nodeName').toString(), "$([TR, TABLE, BODY, HTML])")
+ # prev: -> assertEqual($("div.c").next().first().toString(), "$([P])")
)

No commit comments for this range

Something went wrong with that request. Please try again.