@@ -41,6 +41,18 @@ $traceurRuntime.createClass = createClass;
41
41
$traceurRuntime . superCall = superCall ;
42
42
$traceurRuntime . defaultSuperCall = defaultSuperCall ;
43
43
"use strict" ;
44
+ function is ( first , second ) {
45
+ if ( first === second ) {
46
+ return first !== 0 || second !== 0 || 1 / first === 1 / second ;
47
+ }
48
+ if ( first !== first ) {
49
+ return second !== second ;
50
+ }
51
+ if ( first && typeof first . equals === 'function' ) {
52
+ return first . equals ( second ) ;
53
+ }
54
+ return false ;
55
+ }
44
56
var DELETE = 'delete' ;
45
57
var SHIFT = 5 ;
46
58
var SIZE = 1 << SHIFT ;
@@ -1514,14 +1526,16 @@ function interposeFactory(sequence, separator) {
1514
1526
} ;
1515
1527
return interposedSequence ;
1516
1528
}
1517
- var Cursor = function Cursor ( rootData , keyPath , onChange , value ) {
1518
- value = value ? value : rootData . getIn ( keyPath ) ;
1519
- this . length = value instanceof Sequence ? value . length : null ;
1529
+ var Cursor = function Cursor ( rootData , keyPath , onChange , length ) {
1530
+ this . length = length ;
1520
1531
this . _rootData = rootData ;
1521
1532
this . _keyPath = keyPath ;
1522
1533
this . _onChange = onChange ;
1523
1534
} ;
1524
1535
( $traceurRuntime . createClass ) ( Cursor , {
1536
+ equals : function ( second ) {
1537
+ return is ( this . deref ( ) , second && ( typeof second . deref === 'function' ? second . deref ( ) : second ) ) ;
1538
+ } ,
1525
1539
deref : function ( notSetValue ) {
1526
1540
return this . _rootData . getIn ( this . _keyPath , notSetValue ) ;
1527
1541
} ,
@@ -1588,35 +1602,24 @@ var Cursor = function Cursor(rootData, keyPath, onChange, value) {
1588
1602
} , { } , Sequence ) ;
1589
1603
Cursor . prototype [ DELETE ] = Cursor . prototype . remove ;
1590
1604
Cursor . prototype . getIn = Cursor . prototype . get ;
1605
+ function makeCursor ( rootData , keyPath , onChange , value ) {
1606
+ if ( arguments . length < 4 ) {
1607
+ value = rootData . getIn ( keyPath ) ;
1608
+ }
1609
+ var length = value instanceof Sequence ? value . length : null ;
1610
+ return new Cursor ( rootData , keyPath , onChange , length ) ;
1611
+ }
1591
1612
function wrappedValue ( cursor , key , value ) {
1592
1613
return value instanceof Sequence ? subCursor ( cursor , key , value ) : value ;
1593
1614
}
1594
1615
function subCursor ( cursor , key , value ) {
1595
- return new Cursor ( cursor . _rootData , cursor . _keyPath . concat ( key ) , cursor . _onChange , value ) ;
1616
+ return makeCursor ( cursor . _rootData , cursor . _keyPath . concat ( key ) , cursor . _onChange , value ) ;
1596
1617
}
1597
1618
function updateCursor ( cursor , changeFn , changeKey ) {
1598
1619
var newRootData = cursor . _rootData . updateIn ( cursor . _keyPath , changeKey ? Map . empty ( ) : undefined , changeFn ) ;
1599
1620
var keyPath = cursor . _keyPath || [ ] ;
1600
1621
cursor . _onChange && cursor . _onChange . call ( undefined , newRootData , cursor . _rootData , changeKey ? keyPath . concat ( changeKey ) : keyPath ) ;
1601
- return new Cursor ( newRootData , cursor . _keyPath , cursor . _onChange ) ;
1602
- }
1603
- function is ( first , second ) {
1604
- if ( first instanceof Cursor ) {
1605
- first = first . deref ( ) ;
1606
- }
1607
- if ( second instanceof Cursor ) {
1608
- second = second . deref ( ) ;
1609
- }
1610
- if ( first === second ) {
1611
- return first !== 0 || second !== 0 || 1 / first === 1 / second ;
1612
- }
1613
- if ( first !== first ) {
1614
- return second !== second ;
1615
- }
1616
- if ( first instanceof Sequence ) {
1617
- return first . equals ( second ) ;
1618
- }
1619
- return false ;
1622
+ return makeCursor ( newRootData , cursor . _keyPath , cursor . _onChange ) ;
1620
1623
}
1621
1624
var Map = function Map ( sequence ) {
1622
1625
var map = $Map . empty ( ) ;
@@ -1686,7 +1689,7 @@ var $Map = Map;
1686
1689
} else if ( ! Array . isArray ( keyPath ) ) {
1687
1690
keyPath = [ keyPath ] ;
1688
1691
}
1689
- return new Cursor ( this , keyPath , onChange ) ;
1692
+ return makeCursor ( this , keyPath , onChange ) ;
1690
1693
} ,
1691
1694
withMutations : function ( fn ) {
1692
1695
var mutable = this . asMutable ( ) ;
0 commit comments