Skip to content

Commit 9394918

Browse files
committed
rebuilt
1 parent 1c979eb commit 9394918

8 files changed

+544
-132
lines changed

build/Ractive-legacy.js

+133-30
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,10 @@ var cssTransitionsEnabled, transition, transitionend;
760760

761761
if ( !this.root.lazy ) {
762762
node.addEventListener( 'input', updateModel, false );
763-
}
764763

765-
if ( node.attachEvent ) {
766-
node.addEventListener( 'keyup', updateModel, false );
764+
if ( node.attachEvent ) {
765+
node.addEventListener( 'keyup', updateModel, false );
766+
}
767767
}
768768
};
769769

@@ -2073,7 +2073,7 @@ resolveMustache = function ( keypath ) {
20732073
};
20742074
(function () {
20752075

2076-
var updateListSection, updateContextSection, updateConditionalSection;
2076+
var updateListSection, updateListObjectSection, updateContextSection, updateConditionalSection;
20772077

20782078
updateSection = function ( section, value ) {
20792079
var fragmentOptions;
@@ -2093,15 +2093,19 @@ resolveMustache = function ( keypath ) {
20932093

20942094
// otherwise we need to work out what sort of section we're dealing with
20952095

2096-
// if value is an array, iterate through
2096+
// if value is an array, or an object with an index reference, iterate through
20972097
if ( isArray( value ) ) {
20982098
updateListSection( section, value, fragmentOptions );
20992099
}
21002100

21012101

21022102
// if value is a hash...
21032103
else if ( isObject( value ) ) {
2104-
updateContextSection( section, fragmentOptions );
2104+
if ( section.descriptor.i ) {
2105+
updateListObjectSection( section, value, fragmentOptions );
2106+
} else {
2107+
updateContextSection( section, fragmentOptions );
2108+
}
21052109
}
21062110

21072111

@@ -2112,11 +2116,13 @@ resolveMustache = function ( keypath ) {
21122116
};
21132117

21142118
updateListSection = function ( section, value, fragmentOptions ) {
2115-
var i, fragmentsToRemove;
2119+
var i, length, fragmentsToRemove;
2120+
2121+
length = value.length;
21162122

21172123
// if the array is shorter than it was previously, remove items
2118-
if ( value.length < section.length ) {
2119-
fragmentsToRemove = section.fragments.splice( value.length, section.length - value.length );
2124+
if ( length < section.length ) {
2125+
fragmentsToRemove = section.fragments.splice( length, section.length - length );
21202126

21212127
while ( fragmentsToRemove.length ) {
21222128
fragmentsToRemove.pop().teardown( true );
@@ -2126,9 +2132,9 @@ resolveMustache = function ( keypath ) {
21262132
// otherwise...
21272133
else {
21282134

2129-
if ( value.length > section.length ) {
2135+
if ( length > section.length ) {
21302136
// add any new ones
2131-
for ( i=section.length; i<value.length; i+=1 ) {
2137+
for ( i=section.length; i<length; i+=1 ) {
21322138
// append list item to context stack
21332139
fragmentOptions.contextStack = section.contextStack.concat( section.keypath + '.' + i );
21342140
fragmentOptions.index = i;
@@ -2142,7 +2148,35 @@ resolveMustache = function ( keypath ) {
21422148
}
21432149
}
21442150

2145-
section.length = value.length;
2151+
section.length = length;
2152+
};
2153+
2154+
updateListObjectSection = function ( section, value, fragmentOptions ) {
2155+
var id, fragmentsById;
2156+
2157+
fragmentsById = section.fragmentsById || ( section.fragmentsById = createFromNull() );
2158+
2159+
// remove any fragments that should no longer exist
2160+
for ( id in fragmentsById ) {
2161+
if ( value[ id ] === undefined ) {
2162+
fragmentsById[ id ].teardown( true );
2163+
fragmentsById[ id ] = null;
2164+
}
2165+
}
2166+
2167+
// add any that haven't been created yet
2168+
for ( id in value ) {
2169+
if ( value[ id ] !== undefined && !fragmentsById[ id ] ) {
2170+
fragmentOptions.contextStack = section.contextStack.concat( section.keypath + '.' + id );
2171+
fragmentOptions.index = id;
2172+
2173+
if ( section.descriptor.i ) {
2174+
fragmentOptions.indexRef = section.descriptor.i;
2175+
}
2176+
2177+
fragmentsById[ id ] = section.createFragment( fragmentOptions );
2178+
}
2179+
}
21462180
};
21472181

21482182
updateContextSection = function ( section, fragmentOptions ) {
@@ -2731,12 +2765,26 @@ proto.fire = function ( eventName ) {
27312765

27322766
// wrap object for magic get/set
27332767
wrapProperty = function ( obj, prop, ractive, keypath ) {
2734-
var value, descriptor, get, set, oldGet, oldSet;
2768+
var value, descriptor, get, set, oldGet, oldSet, ractives, keypathsByGuid;
27352769

27362770
descriptor = Object.getOwnPropertyDescriptor( obj, prop );
27372771

27382772
if ( descriptor ) {
2739-
if ( descriptor.set && descriptor.set[ ractive._guid + keypath ] ) {
2773+
if ( descriptor.set && ( ractives = descriptor.set.ractives ) ) {
2774+
console.log( 'here' );
2775+
2776+
// register this ractive to this object
2777+
if ( ractives.indexOf( ractive ) === -1 ) {
2778+
ractives[ ractives.length ] = ractive;
2779+
}
2780+
2781+
// register this keypath to this object
2782+
keypathsByGuid = descriptor.set[ ractive._guid ] || ( descriptor.set[ ractive._guid ] = []);
2783+
2784+
if ( keypathsByGuid.indexOf( keypath ) === -1 ) {
2785+
keypathsByGuid[ keypathsByGuid.length ] = keypath;
2786+
}
2787+
27402788
return; // already wrapped
27412789
}
27422790

@@ -2755,17 +2803,34 @@ proto.fire = function ( eventName ) {
27552803
};
27562804

27572805
set = function ( newValue ) {
2806+
var ractives, ractive, keypaths, i, j;
2807+
27582808
value = newValue;
27592809

2760-
if ( !ractive.muggleSet ) {
2761-
ractive.magicSet = true;
2762-
ractive.set( keypath, newValue );
2763-
ractive.magicSet = false;
2810+
ractives = set.ractives;
2811+
2812+
i = ractives.length;
2813+
while ( i-- ) {
2814+
ractive = ractives[i];
2815+
2816+
if ( !ractive.muggleSet ) {
2817+
ractive.magicSet = true;
2818+
2819+
keypaths = set[ ractive._guid ];
2820+
j = keypaths.length;
2821+
2822+
while ( j-- ) {
2823+
ractive.set( keypaths[j], newValue );
2824+
}
2825+
2826+
ractive.magicSet = false;
2827+
}
27642828
}
27652829
};
27662830

27672831
// prevent rewrapping
2768-
set[ ractive._guid + keypath ] = true;
2832+
set.ractives = [ ractive ];
2833+
set[ ractive._guid ] = [ keypath ];
27692834

27702835
Object.defineProperty( obj, prop, { get: get, set: set, enumerable: true, configurable: true });
27712836
}
@@ -2800,7 +2865,10 @@ proto.fire = function ( eventName ) {
28002865

28012866
return {
28022867
teardown: function () {
2868+
var value = obj[ prop ];
2869+
28032870
Object.defineProperty( obj, prop, descriptor );
2871+
obj[ prop ] = value;
28042872
}
28052873
};
28062874
};
@@ -3827,7 +3895,7 @@ eventDefinitions.tap = function ( node, fire ) {
38273895
timeThreshold = 400; // maximum milliseconds between down and up before cancel
38283896

38293897
mousedown = function ( event ) {
3830-
var currentTarget, x, y, up, move, cancel;
3898+
var currentTarget, x, y, pointerId, up, move, cancel;
38313899

38323900
if ( event.which != 1) {
38333901
return;
@@ -3836,8 +3904,14 @@ eventDefinitions.tap = function ( node, fire ) {
38363904
x = event.clientX;
38373905
y = event.clientY;
38383906
currentTarget = this;
3907+
// This will be null for mouse events.
3908+
pointerId = event.pointerId;
38393909

38403910
up = function ( event ) {
3911+
if ( event.pointerId != pointerId ) {
3912+
return;
3913+
}
3914+
38413915
fire({
38423916
node: currentTarget,
38433917
original: event
@@ -3847,23 +3921,49 @@ eventDefinitions.tap = function ( node, fire ) {
38473921
};
38483922

38493923
move = function ( event ) {
3924+
if ( event.pointerId != pointerId ) {
3925+
return;
3926+
}
3927+
38503928
if ( ( Math.abs( event.clientX - x ) >= distanceThreshold ) || ( Math.abs( event.clientY - y ) >= distanceThreshold ) ) {
38513929
cancel();
38523930
}
38533931
};
38543932

38553933
cancel = function () {
3934+
node.removeEventListener( 'MSPointerUp', up, false );
3935+
doc.removeEventListener( 'MSPointerMove', move, false );
3936+
doc.removeEventListener( 'MSPointerCancel', cancel, false );
3937+
node.removeEventListener( 'pointerup', up, false );
3938+
doc.removeEventListener( 'pointermove', move, false );
3939+
doc.removeEventListener( 'pointercancel', cancel, false );
38563940
node.removeEventListener( 'click', up, false );
38573941
doc.removeEventListener( 'mousemove', move, false );
38583942
};
38593943

3860-
node.addEventListener( 'click', up, false );
3861-
doc.addEventListener( 'mousemove', move, false );
3944+
if ( window.navigator.pointerEnabled ) {
3945+
node.addEventListener( 'pointerup', up, false );
3946+
doc.addEventListener( 'pointermove', move, false );
3947+
doc.addEventListener( 'pointercancel', cancel, false );
3948+
} else if ( window.navigator.msPointerEnabled ) {
3949+
node.addEventListener( 'MSPointerUp', up, false );
3950+
doc.addEventListener( 'MSPointerMove', move, false );
3951+
doc.addEventListener( 'MSPointerCancel', cancel, false );
3952+
} else {
3953+
node.addEventListener( 'click', up, false );
3954+
doc.addEventListener( 'mousemove', move, false );
3955+
}
38623956

38633957
setTimeout( cancel, timeThreshold );
38643958
};
38653959

3866-
node.addEventListener( 'mousedown', mousedown, false );
3960+
if ( window.navigator.pointerEnabled ) {
3961+
node.addEventListener( 'pointerdown', mousedown, false );
3962+
} else if ( window.navigator.msPointerEnabled ) {
3963+
node.addEventListener( 'MSPointerDown', mousedown, false );
3964+
} else {
3965+
node.addEventListener( 'mousedown', mousedown, false );
3966+
}
38673967

38683968

38693969
touchstart = function ( event ) {
@@ -4483,13 +4583,7 @@ Ractive = function ( options ) {
44834583
}
44844584
}
44854585
}
4486-
4487-
// Unpack string-based partials, if necessary
4488-
for ( key in this.partials ) {
4489-
if ( hasOwn.call( this.partials, key ) && this.partials[ key ].length === 1 && typeof this.partials[ key ][0] === 'string' ) {
4490-
this.partials[ key ] = this.partials[ key ][0];
4491-
}
4492-
}
4586+
44934587

44944588
// temporarily disable transitions, if noIntro flag is set
44954589
this.transitionsEnabled = ( options.noIntro ? false : options.transitionsEnabled );
@@ -6276,9 +6370,18 @@ DomSection.prototype = {
62766370
},
62776371

62786372
teardownFragments: function ( detach ) {
6373+
var id;
6374+
62796375
while ( this.fragments.length ) {
62806376
this.fragments.shift().teardown( detach );
62816377
}
6378+
6379+
if ( this.fragmentsById ) {
6380+
for ( id in this.fragmentsById ) {
6381+
this.fragmentsById[ id ].teardown();
6382+
this.fragmentsById[ id ] = null;
6383+
}
6384+
}
62826385
},
62836386

62846387
render: function ( value ) {

build/Ractive-legacy.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)