@@ -1765,8 +1765,8 @@ function $ParseProvider() {
1765
1765
if ( parsedExpression . constant ) {
1766
1766
parsedExpression . $$watchDelegate = constantWatchDelegate ;
1767
1767
} else if ( oneTime ) {
1768
- parsedExpression . $$watchDelegate = parsedExpression . literal ?
1769
- oneTimeLiteralWatchDelegate : oneTimeWatchDelegate ;
1768
+ parsedExpression . oneTime = true ;
1769
+ parsedExpression . $$watchDelegate = oneTimeWatchDelegate ;
1770
1770
} else if ( parsedExpression . inputs ) {
1771
1771
parsedExpression . $$watchDelegate = inputsWatchDelegate ;
1772
1772
}
@@ -1852,6 +1852,7 @@ function $ParseProvider() {
1852
1852
}
1853
1853
1854
1854
function oneTimeWatchDelegate ( scope , listener , objectEquality , parsedExpression , prettyPrintExpression ) {
1855
+ var isDone = parsedExpression . literal ? isAllDefined : isDefined ;
1855
1856
var unwatch , lastValue ;
1856
1857
if ( parsedExpression . inputs ) {
1857
1858
unwatch = inputsWatchDelegate ( scope , oneTimeListener , objectEquality , parsedExpression , prettyPrintExpression ) ;
@@ -1868,42 +1869,23 @@ function $ParseProvider() {
1868
1869
if ( isFunction ( listener ) ) {
1869
1870
listener ( value , old , scope ) ;
1870
1871
}
1871
- if ( isDefined ( value ) ) {
1872
+ if ( isDone ( value ) ) {
1872
1873
scope . $$postDigest ( function ( ) {
1873
- if ( isDefined ( lastValue ) ) {
1874
+ if ( isDone ( lastValue ) ) {
1874
1875
unwatch ( ) ;
1875
1876
}
1876
1877
} ) ;
1877
1878
}
1878
1879
}
1879
1880
}
1880
1881
1881
- function oneTimeLiteralWatchDelegate ( scope , listener , objectEquality , parsedExpression ) {
1882
- var unwatch , lastValue ;
1883
- unwatch = scope . $watch ( function oneTimeWatch ( scope ) {
1884
- return parsedExpression ( scope ) ;
1885
- } , function oneTimeListener ( value , old , scope ) {
1886
- lastValue = value ;
1887
- if ( isFunction ( listener ) ) {
1888
- listener ( value , old , scope ) ;
1889
- }
1890
- if ( isAllDefined ( value ) ) {
1891
- scope . $$postDigest ( function ( ) {
1892
- if ( isAllDefined ( lastValue ) ) unwatch ( ) ;
1893
- } ) ;
1894
- }
1895
- } , objectEquality ) ;
1896
-
1897
- return unwatch ;
1898
-
1899
1882
function isAllDefined ( value ) {
1900
1883
var allDefined = true ;
1901
1884
forEach ( value , function ( val ) {
1902
1885
if ( ! isDefined ( val ) ) allDefined = false ;
1903
1886
} ) ;
1904
1887
return allDefined ;
1905
1888
}
1906
- }
1907
1889
1908
1890
function constantWatchDelegate ( scope , listener , objectEquality , parsedExpression ) {
1909
1891
var unwatch = scope . $watch ( function constantWatch ( scope ) {
@@ -1918,22 +1900,28 @@ function $ParseProvider() {
1918
1900
var watchDelegate = parsedExpression . $$watchDelegate ;
1919
1901
var useInputs = false ;
1920
1902
1921
- var regularWatch =
1922
- watchDelegate !== oneTimeLiteralWatchDelegate &&
1923
- watchDelegate !== oneTimeWatchDelegate ;
1903
+ var isDone = parsedExpression . literal ? isAllDefined : isDefined ;
1924
1904
1925
- var fn = regularWatch ? function regularInterceptedExpression ( scope , locals , assign , inputs ) {
1905
+ function regularInterceptedExpression ( scope , locals , assign , inputs ) {
1926
1906
var value = useInputs && inputs ? inputs [ 0 ] : parsedExpression ( scope , locals , assign , inputs ) ;
1927
1907
return interceptorFn ( value , scope , locals ) ;
1928
- } : function oneTimeInterceptedExpression ( scope , locals , assign , inputs ) {
1929
- var value = parsedExpression ( scope , locals , assign , inputs ) ;
1908
+ }
1909
+
1910
+ function oneTimeInterceptedExpression ( scope , locals , assign , inputs ) {
1911
+ var value = useInputs && inputs ? inputs [ 0 ] : parsedExpression ( scope , locals , assign , inputs ) ;
1930
1912
var result = interceptorFn ( value , scope , locals ) ;
1931
1913
// we only return the interceptor's result if the
1932
1914
// initial value is defined (for bind-once)
1933
- return isDefined ( value ) ? result : value ;
1934
- } ;
1915
+ return isDone ( value ) ? result : value ;
1916
+ }
1917
+
1918
+ var fn = parsedExpression . oneTime ? oneTimeInterceptedExpression : regularInterceptedExpression ;
1919
+
1920
+ // Propogate the literal/oneTime attributes
1921
+ fn . literal = parsedExpression . literal ;
1922
+ fn . oneTime = parsedExpression . oneTime ;
1935
1923
1936
- // Propagate $$watchDelegates other then inputsWatchDelegate
1924
+ // Propagate or create inputs / $$watchDelegates
1937
1925
useInputs = ! parsedExpression . inputs ;
1938
1926
if ( watchDelegate && watchDelegate !== inputsWatchDelegate ) {
1939
1927
fn . $$watchDelegate = watchDelegate ;
0 commit comments