@@ -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,39 +1944,45 @@ function $ParseProvider() {
1937
1944
return parsedExpression ;
1938
1945
}
1939
1946
1940
- function addInterceptor ( parsedExpression , interceptorFn ) {
1941
- if ( ! interceptorFn ) return parsedExpression ;
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 ;
1942
1952
1943
- var useInputs = false ;
1953
+ return chainedInterceptor ;
1954
+ }
1944
1955
1945
- var isDone = parsedExpression . literal ? isAllDefined : isDefined ;
1956
+ function addInterceptor ( exp , interceptorFn ) {
1957
+ if ( ! interceptorFn ) return exp ;
1946
1958
1947
- function regularInterceptedExpression ( scope , locals , assign , inputs ) {
1948
- var value = useInputs && inputs ? inputs [ 0 ] : parsedExpression ( scope , locals , assign , inputs ) ;
1949
- return interceptorFn ( value , scope , locals ) ;
1950
- }
1959
+ var intercepted = exp . $$intercepted || exp ;
1960
+ var interceptor = exp . $$interceptor
1961
+ ? chainInterceptors ( exp . $$interceptor , interceptorFn )
1962
+ : interceptorFn ;
1951
1963
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
- }
1964
+ var useInputs = false ;
1965
+
1966
+ var fn = function regularInterceptedExpression ( scope , locals , assign , inputs ) {
1967
+ var value = useInputs && inputs ? inputs [ 0 ] : intercepted ( scope , locals , assign , inputs ) ;
1968
+ return interceptor ( value , scope , locals ) ;
1969
+ } ;
1959
1970
1960
- var fn = parsedExpression . oneTime ? oneTimeInterceptedExpression : regularInterceptedExpression ;
1971
+ // Maintain references to the interceptor/intercepted
1972
+ fn . $$intercepted = intercepted ;
1973
+ fn . $$interceptor = interceptor ;
1961
1974
1962
1975
// Propogate the literal/oneTime/constant attributes
1963
- fn . literal = parsedExpression . literal ;
1964
- fn . oneTime = parsedExpression . oneTime ;
1965
- fn . constant = parsedExpression . constant ;
1976
+ fn . literal = intercepted . literal ;
1977
+ fn . oneTime = intercepted . oneTime ;
1978
+ fn . constant = intercepted . constant ;
1966
1979
1967
1980
// Treat the interceptor like filters.
1968
1981
// If it is not $stateful then only watch its inputs.
1969
1982
// If the expression itself has no inputs then use the full expression as an input.
1970
- if ( ! interceptorFn . $stateful ) {
1971
- useInputs = ! parsedExpression . inputs ;
1972
- fn . inputs = ( parsedExpression . inputs ? parsedExpression . inputs : [ parsedExpression ] ) . map ( function ( e ) {
1983
+ if ( ! interceptor . $stateful ) {
1984
+ useInputs = ! intercepted . inputs ;
1985
+ fn . inputs = ( intercepted . inputs ? intercepted . inputs : [ intercepted ] ) . map ( function ( e ) {
1973
1986
// Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
1974
1987
// potentially non-pure interceptor function.
1975
1988
if ( e . isPure === PURITY_RELATIVE ) {
0 commit comments