tests are no longer failing :)
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
class YList
|
||||
|
||||
#
|
||||
# @private
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
#
|
||||
constructor: (list)->
|
||||
if not list?
|
||||
@_list = []
|
||||
else if list.constructor is Array
|
||||
@_list = list
|
||||
else
|
||||
throw new Error "Y.List expects an Array as a parameter"
|
||||
|
||||
_name: "List"
|
||||
|
||||
_getModel: (types, ops)->
|
||||
if not @_model?
|
||||
@_model = new ops.ListManager(@).execute()
|
||||
@insert 0, @_list
|
||||
delete @_list
|
||||
@_model
|
||||
|
||||
_setModel: (@_model)->
|
||||
delete @_list
|
||||
|
||||
val: ()->
|
||||
@_model.val.apply @_model, arguments
|
||||
|
||||
observe: ()->
|
||||
@_model.observe.apply @_model, arguments
|
||||
@
|
||||
|
||||
unobserve: ()->
|
||||
@_model.unobserve.apply @_model, arguments
|
||||
@
|
||||
|
||||
#
|
||||
# Inserts a Array into the list.
|
||||
#
|
||||
# @return {ListManager Type} This String object.
|
||||
#
|
||||
insert: (position, content)->
|
||||
if typeof position isnt "number"
|
||||
throw new Error "Y.List.insert expects a Number as the first parameter!"
|
||||
@_model.insert position, content
|
||||
@
|
||||
|
||||
delete: (position, length)->
|
||||
@_model.delete position, length
|
||||
@
|
||||
|
||||
if window?
|
||||
if window.Y?
|
||||
window.Y.List = YList
|
||||
else
|
||||
throw new Error "You must first import Y!"
|
||||
|
||||
if module?
|
||||
module.exports = YList
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@ class YObject
|
||||
|
||||
observe: (f)->
|
||||
@_model.observe f
|
||||
@
|
||||
|
||||
unobserve: (f)->
|
||||
@_model.unobserve f
|
||||
@
|
||||
|
||||
#
|
||||
# @overload val()
|
||||
@@ -57,6 +62,7 @@ class YObject
|
||||
|
||||
delete: (name)->
|
||||
@_model.delete(name)
|
||||
@
|
||||
|
||||
if window?
|
||||
if window.Y?
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#
|
||||
# Handles a String-like data structures with support for insert/delete at a word-position.
|
||||
# @note Currently, only Text is supported!
|
||||
#
|
||||
class YText
|
||||
|
||||
@@ -59,7 +58,7 @@ class YText
|
||||
if content.constructor isnt String
|
||||
throw new Error "Y.String.insert expects a String as the second parameter!"
|
||||
if typeof position isnt "number"
|
||||
throw new Error "Y.String.insert expects a Number as the second parameter!"
|
||||
throw new Error "Y.String.insert expects a Number as the first parameter!"
|
||||
if content.length > 0
|
||||
ith = @_model.getOperationByPosition position
|
||||
# the (i-1)th character. e.g. "abc" the 1th character is "a"
|
||||
|
||||
Reference in New Issue
Block a user