@@ -1884,28 +1884,35 @@ function $ParseProvider() {
1884
1884
function oneTimeWatchDelegate ( scope , listener , objectEquality , parsedExpression , prettyPrintExpression ) {
1885
1885
var isDone = parsedExpression . literal ? isAllDefined : isDefined ;
1886
1886
var unwatch , lastValue ;
1887
- if ( parsedExpression . inputs ) {
1888
- unwatch = inputsWatchDelegate ( scope , oneTimeListener , objectEquality , parsedExpression , prettyPrintExpression ) ;
1889
- } else {
1890
- unwatch = scope . $watch ( oneTimeWatch , oneTimeListener , objectEquality ) ;
1891
- }
1887
+
1888
+ var exp = parsedExpression . $$intercepted || parsedExpression ;
1889
+ var post = parsedExpression . $$interceptor || identity ;
1890
+
1891
+ // Propogate the literal/inputs/constant attributes
1892
+ // ... but not oneTime since we are handling it
1893
+ oneTimeWatch . literal = parsedExpression . literal ;
1894
+ oneTimeWatch . constant = parsedExpression . constant ;
1895
+ oneTimeWatch . inputs = ! post . $stateful && exp . inputs ;
1896
+
1897
+ // Allow other delegates to run on this wrapped expression
1898
+ addWatchDelegate ( oneTimeWatch ) ;
1899
+
1900
+ unwatch = scope . $watch ( oneTimeWatch , listener , objectEquality , prettyPrintExpression ) ;
1901
+
1892
1902
return unwatch ;
1893
1903
1894
- function oneTimeWatch ( scope ) {
1895
- return parsedExpression ( scope ) ;
1896
- }
1897
- function oneTimeListener ( value , old , scope ) {
1898
- lastValue = value ;
1899
- if ( isFunction ( listener ) ) {
1900
- listener ( value , old , scope ) ;
1904
+ function unwatchIfDone ( ) {
1905
+ if ( isDone ( lastValue ) ) {
1906
+ unwatch ( ) ;
1901
1907
}
1902
- if ( isDone ( value ) ) {
1903
- scope . $$postDigest ( function ( ) {
1904
- if ( isDone ( lastValue ) ) {
1905
- unwatch ( ) ;
1906
- }
1907
- } ) ;
1908
+ }
1909
+
1910
+ function oneTimeWatch ( scope , locals , assign , inputs ) {
1911
+ lastValue = exp ( scope , locals , assign , inputs ) ;
1912
+ if ( isDone ( lastValue ) ) {
1913
+ scope . $$postDigest ( unwatchIfDone ) ;
1908
1914
}
1915
+ return post ( lastValue , scope , locals ) ;
1909
1916
}
1910
1917
}
1911
1918
@@ -1937,27 +1944,35 @@ function $ParseProvider() {
1937
1944
return parsedExpression ;
1938
1945
}
1939
1946
1947
+ function chainInterceptors ( first , second ) {
1948
+ function chainedInterceptor ( value , scope , locals ) {
1949
+ return second ( first ( value , scope , locals ) , scope , locals ) ;
1950
+ }
1951
+ chainedInterceptor . $stateful = first . $stateful || second . $stateful ;
1952
+
1953
+ return chainedInterceptor ;
1954
+ }
1955
+
1940
1956
function addInterceptor ( parsedExpression , interceptorFn ) {
1941
1957
if ( ! interceptorFn ) return parsedExpression ;
1942
1958
1943
- var useInputs = false ;
1959
+ // Extract any existing interceptors out of the parsedExpression
1960
+ // to ensure the original parsedExpression is always the $$intercepted
1961
+ if ( parsedExpression . $$interceptor ) {
1962
+ interceptorFn = chainInterceptors ( parsedExpression . $$interceptor , interceptorFn ) ;
1963
+ parsedExpression = parsedExpression . $$intercepted || parsedExpression ;
1964
+ }
1944
1965
1945
- var isDone = parsedExpression . literal ? isAllDefined : isDefined ;
1966
+ var useInputs = false ;
1946
1967
1947
- function regularInterceptedExpression ( scope , locals , assign , inputs ) {
1968
+ var fn = function interceptedExpression ( scope , locals , assign , inputs ) {
1948
1969
var value = useInputs && inputs ? inputs [ 0 ] : parsedExpression ( scope , locals , assign , inputs ) ;
1949
1970
return interceptorFn ( value , scope , locals ) ;
1950
- }
1951
-
1952
- function oneTimeInterceptedExpression ( scope , locals , assign , inputs ) {
1953
- var value = useInputs && inputs ? inputs [ 0 ] : parsedExpression ( scope , locals , assign , inputs ) ;
1954
- var result = interceptorFn ( value , scope , locals ) ;
1955
- // we only return the interceptor's result if the
1956
- // initial value is defined (for bind-once)
1957
- return isDone ( value ) ? result : value ;
1958
- }
1971
+ } ;
1959
1972
1960
- var fn = parsedExpression . oneTime ? oneTimeInterceptedExpression : regularInterceptedExpression ;
1973
+ // Maintain references to the interceptor/intercepted
1974
+ fn . $$intercepted = parsedExpression ;
1975
+ fn . $$interceptor = interceptorFn ;
1961
1976
1962
1977
// Propogate the literal/oneTime/constant attributes
1963
1978
fn . literal = parsedExpression . literal ;
0 commit comments