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