@@ -1526,101 +1526,6 @@ function interposeFactory(sequence, separator) {
1526
1526
} ;
1527
1527
return interposedSequence ;
1528
1528
}
1529
- var Cursor = function Cursor ( rootData , keyPath , onChange , length ) {
1530
- this . length = length ;
1531
- this . _rootData = rootData ;
1532
- this . _keyPath = keyPath ;
1533
- this . _onChange = onChange ;
1534
- } ;
1535
- ( $traceurRuntime . createClass ) ( Cursor , {
1536
- equals : function ( second ) {
1537
- return is ( this . deref ( ) , second && ( typeof second . deref === 'function' ? second . deref ( ) : second ) ) ;
1538
- } ,
1539
- deref : function ( notSetValue ) {
1540
- return this . _rootData . getIn ( this . _keyPath , notSetValue ) ;
1541
- } ,
1542
- get : function ( key , notSetValue ) {
1543
- if ( Array . isArray ( key ) && key . length === 0 ) {
1544
- return this ;
1545
- }
1546
- var value = this . _rootData . getIn ( this . _keyPath . concat ( key ) , NOT_SET ) ;
1547
- return value === NOT_SET ? notSetValue : wrappedValue ( this , key , value ) ;
1548
- } ,
1549
- set : function ( key , value ) {
1550
- return updateCursor ( this , ( function ( m ) {
1551
- return m . set ( key , value ) ;
1552
- } ) , key ) ;
1553
- } ,
1554
- remove : function ( key ) {
1555
- return updateCursor ( this , ( function ( m ) {
1556
- return m . remove ( key ) ;
1557
- } ) , key ) ;
1558
- } ,
1559
- clear : function ( ) {
1560
- return updateCursor ( this , ( function ( m ) {
1561
- return m . clear ( ) ;
1562
- } ) ) ;
1563
- } ,
1564
- update : function ( keyOrFn , notSetValue , updater ) {
1565
- return arguments . length === 1 ? updateCursor ( this , keyOrFn ) : updateCursor ( this , ( function ( map ) {
1566
- return map . update ( keyOrFn , notSetValue , updater ) ;
1567
- } ) , keyOrFn ) ;
1568
- } ,
1569
- withMutations : function ( fn ) {
1570
- return updateCursor ( this , ( function ( m ) {
1571
- return ( m || Map . empty ( ) ) . withMutations ( fn ) ;
1572
- } ) ) ;
1573
- } ,
1574
- cursor : function ( subKey ) {
1575
- return Array . isArray ( subKey ) && subKey . length === 0 ? this : subCursor ( this , subKey ) ;
1576
- } ,
1577
- __iterate : function ( fn , reverse ) {
1578
- var $__0 = this ;
1579
- var deref = this . deref ( ) ;
1580
- return deref && deref . __iterate ? deref . __iterate ( ( function ( v , k ) {
1581
- return fn ( wrappedValue ( $__0 , k , v ) , k , $__0 ) ;
1582
- } ) , reverse ) : 0 ;
1583
- } ,
1584
- __iterator : function ( type , reverse ) {
1585
- var $__0 = this ;
1586
- var deref = this . deref ( ) ;
1587
- var iterator = deref && deref . __iterator && deref . __iterator ( ITERATE_ENTRIES , reverse ) ;
1588
- return new Iterator ( ( function ( ) {
1589
- if ( ! iterator ) {
1590
- return iteratorDone ( ) ;
1591
- }
1592
- var step = iterator . next ( ) ;
1593
- if ( step . done ) {
1594
- return step ;
1595
- }
1596
- var entry = step . value ;
1597
- var k = entry [ 0 ] ;
1598
- var v = entry [ 1 ] ;
1599
- return iteratorValue ( type , k , wrappedValue ( $__0 , k , v ) , step ) ;
1600
- } ) ) ;
1601
- }
1602
- } , { } , Sequence ) ;
1603
- Cursor . prototype [ DELETE ] = Cursor . prototype . remove ;
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
- }
1612
- function wrappedValue ( cursor , key , value ) {
1613
- return value instanceof Sequence ? subCursor ( cursor , key , value ) : value ;
1614
- }
1615
- function subCursor ( cursor , key , value ) {
1616
- return makeCursor ( cursor . _rootData , cursor . _keyPath . concat ( key ) , cursor . _onChange , value ) ;
1617
- }
1618
- function updateCursor ( cursor , changeFn , changeKey ) {
1619
- var newRootData = cursor . _rootData . updateIn ( cursor . _keyPath , changeKey ? Map . empty ( ) : undefined , changeFn ) ;
1620
- var keyPath = cursor . _keyPath || [ ] ;
1621
- cursor . _onChange && cursor . _onChange . call ( undefined , newRootData , cursor . _rootData , changeKey ? keyPath . concat ( changeKey ) : keyPath ) ;
1622
- return makeCursor ( newRootData , cursor . _keyPath , cursor . _onChange ) ;
1623
- }
1624
1529
var Map = function Map ( sequence ) {
1625
1530
var map = $Map . empty ( ) ;
1626
1531
return sequence ? sequence . constructor === $Map ? sequence : map . merge ( sequence ) : map ;
@@ -1640,12 +1545,12 @@ var $Map = Map;
1640
1545
return updateMap ( this , k , NOT_SET ) ;
1641
1546
} ,
1642
1547
update : function ( k , notSetValue , updater ) {
1643
- return arguments . length === 1 ? this . updateIn ( [ ] , null , k ) : this . updateIn ( [ k ] , notSetValue , updater ) ;
1548
+ return arguments . length === 1 ? this . updateIn ( [ ] , undefined , k ) : this . updateIn ( [ k ] , notSetValue , updater ) ;
1644
1549
} ,
1645
1550
updateIn : function ( keyPath , notSetValue , updater ) {
1646
- var $__14 ;
1647
1551
if ( ! updater ) {
1648
- ( $__14 = [ notSetValue , updater ] , updater = $__14 [ 0 ] , notSetValue = $__14 [ 1 ] , $__14 ) ;
1552
+ updater = notSetValue ;
1553
+ notSetValue = undefined ;
1649
1554
}
1650
1555
return updateInDeepMap ( this , keyPath , notSetValue , updater , 0 ) ;
1651
1556
} ,
@@ -1680,15 +1585,8 @@ var $Map = Map;
1680
1585
seqs [ $__5 - 1 ] = arguments [ $__5 ] ;
1681
1586
return mergeIntoMapWith ( this , deepMerger ( merger ) , seqs ) ;
1682
1587
} ,
1683
- cursor : function ( keyPath , onChange ) {
1684
- if ( ! onChange && typeof keyPath === 'function' ) {
1685
- onChange = keyPath ;
1686
- keyPath = [ ] ;
1687
- } else if ( arguments . length === 0 ) {
1688
- keyPath = [ ] ;
1689
- } else if ( ! Array . isArray ( keyPath ) ) {
1690
- keyPath = [ keyPath ] ;
1691
- }
1588
+ cursor : function ( maybeKeyPath , onChange ) {
1589
+ var keyPath = arguments . length === 0 || typeof maybeKeyPath === 'function' && ( onChange = maybeKeyPath ) ? [ ] : Array . isArray ( maybeKeyPath ) ? maybeKeyPath : [ maybeKeyPath ] ;
1692
1590
return makeCursor ( this , keyPath , onChange ) ;
1693
1591
} ,
1694
1592
withMutations : function ( fn ) {
@@ -2167,6 +2065,116 @@ function spliceOut(array, idx, canEdit) {
2167
2065
var MAX_BITMAP_SIZE = SIZE / 2 ;
2168
2066
var MIN_ARRAY_SIZE = SIZE / 4 ;
2169
2067
var EMPTY_MAP ;
2068
+ var Cursor = function Cursor ( rootData , keyPath , onChange , length ) {
2069
+ this . length = length ;
2070
+ this . _rootData = rootData ;
2071
+ this . _keyPath = keyPath ;
2072
+ this . _onChange = onChange ;
2073
+ } ;
2074
+ ( $traceurRuntime . createClass ) ( Cursor , {
2075
+ equals : function ( second ) {
2076
+ return is ( this . deref ( ) , second && ( typeof second . deref === 'function' ? second . deref ( ) : second ) ) ;
2077
+ } ,
2078
+ deref : function ( notSetValue ) {
2079
+ return this . _rootData . getIn ( this . _keyPath , notSetValue ) ;
2080
+ } ,
2081
+ get : function ( key , notSetValue ) {
2082
+ return this . getIn ( [ key ] , notSetValue ) ;
2083
+ } ,
2084
+ getIn : function ( searchKeyPath , notSetValue ) {
2085
+ if ( ! searchKeyPath || ( Array . isArray ( searchKeyPath ) && searchKeyPath . length === 0 ) ) {
2086
+ return this ;
2087
+ }
2088
+ var value = this . _rootData . getIn ( this . _keyPath . concat ( searchKeyPath ) , NOT_SET ) ;
2089
+ return value === NOT_SET ? notSetValue : wrappedValue ( this , searchKeyPath , value ) ;
2090
+ } ,
2091
+ set : function ( key , value ) {
2092
+ return updateCursor ( this , ( function ( m ) {
2093
+ return m . set ( key , value ) ;
2094
+ } ) , key ) ;
2095
+ } ,
2096
+ remove : function ( key ) {
2097
+ return updateCursor ( this , ( function ( m ) {
2098
+ return m . remove ( key ) ;
2099
+ } ) , key ) ;
2100
+ } ,
2101
+ update : function ( keyOrFn , notSetValue , updater ) {
2102
+ return arguments . length === 1 ? updateCursor ( this , keyOrFn ) : updateCursor ( this , ( function ( map ) {
2103
+ return map . update ( keyOrFn , notSetValue , updater ) ;
2104
+ } ) , keyOrFn ) ;
2105
+ } ,
2106
+ updateIn : function ( keyPath , notSetValue , updater ) {
2107
+ return updateCursor ( this , ( function ( m ) {
2108
+ return m . updateIn ( keyPath , notSetValue , updater ) ;
2109
+ } ) , keyPath ) ;
2110
+ } ,
2111
+ clear : function ( ) {
2112
+ return updateCursor ( this , ( function ( m ) {
2113
+ return m . clear ( ) ;
2114
+ } ) ) ;
2115
+ } ,
2116
+ cursor : function ( maybeKeyPath , onChange ) {
2117
+ var keyPath = arguments . length === 0 || typeof maybeKeyPath === 'function' && ( onChange = maybeKeyPath ) ? [ ] : Array . isArray ( maybeKeyPath ) ? maybeKeyPath : [ maybeKeyPath ] ;
2118
+ if ( ! onChange ) {
2119
+ if ( keyPath . length === 0 ) {
2120
+ return this ;
2121
+ }
2122
+ return subCursor ( this , keyPath ) ;
2123
+ }
2124
+ return makeCursor ( this , keyPath , onChange , this . deref ( ) . getIn ( keyPath ) ) ;
2125
+ } ,
2126
+ withMutations : function ( fn ) {
2127
+ return updateCursor ( this , ( function ( m ) {
2128
+ return ( m || Map . empty ( ) ) . withMutations ( fn ) ;
2129
+ } ) ) ;
2130
+ } ,
2131
+ __iterate : function ( fn , reverse ) {
2132
+ var $__0 = this ;
2133
+ var deref = this . deref ( ) ;
2134
+ return deref && deref . __iterate ? deref . __iterate ( ( function ( v , k ) {
2135
+ return fn ( wrappedValue ( $__0 , k , v ) , k , $__0 ) ;
2136
+ } ) , reverse ) : 0 ;
2137
+ } ,
2138
+ __iterator : function ( type , reverse ) {
2139
+ var $__0 = this ;
2140
+ var deref = this . deref ( ) ;
2141
+ var iterator = deref && deref . __iterator && deref . __iterator ( ITERATE_ENTRIES , reverse ) ;
2142
+ return new Iterator ( ( function ( ) {
2143
+ if ( ! iterator ) {
2144
+ return iteratorDone ( ) ;
2145
+ }
2146
+ var step = iterator . next ( ) ;
2147
+ if ( step . done ) {
2148
+ return step ;
2149
+ }
2150
+ var entry = step . value ;
2151
+ var k = entry [ 0 ] ;
2152
+ var v = entry [ 1 ] ;
2153
+ return iteratorValue ( type , k , wrappedValue ( $__0 , k , v ) , step ) ;
2154
+ } ) ) ;
2155
+ }
2156
+ } , { } , Sequence ) ;
2157
+ Cursor . prototype [ DELETE ] = Cursor . prototype . remove ;
2158
+ function makeCursor ( rootData , keyPath , onChange , value ) {
2159
+ if ( arguments . length < 4 ) {
2160
+ value = rootData . getIn ( keyPath ) ;
2161
+ }
2162
+ var length = value instanceof Sequence ? value . length : null ;
2163
+ return new Cursor ( rootData , keyPath , onChange , length ) ;
2164
+ }
2165
+ function wrappedValue ( cursor , key , value ) {
2166
+ return value instanceof Sequence ? subCursor ( cursor , key , value ) : value ;
2167
+ }
2168
+ function subCursor ( cursor , key , value ) {
2169
+ return makeCursor ( cursor . _rootData , cursor . _keyPath . concat ( key ) , cursor . _onChange , value ) ;
2170
+ }
2171
+ function updateCursor ( cursor , changeFn , changeKey ) {
2172
+ var updatingSelf = arguments . length < 3 || ( Array . isArray ( changeKey ) && changeKey . length === 0 ) ;
2173
+ var newRootData = cursor . _rootData . updateIn ( cursor . _keyPath , updatingSelf ? undefined : Map . empty ( ) , changeFn ) ;
2174
+ var keyPath = cursor . _keyPath || [ ] ;
2175
+ cursor . _onChange && cursor . _onChange . call ( undefined , newRootData , cursor . _rootData , updatingSelf ? keyPath : keyPath . concat ( changeKey ) ) ;
2176
+ return makeCursor ( newRootData , cursor . _keyPath , cursor . _onChange ) ;
2177
+ }
2170
2178
var Vector = function Vector ( ) {
2171
2179
for ( var values = [ ] ,
2172
2180
$__6 = 0 ; $__6 < arguments . length ; $__6 ++ )
0 commit comments