在SW-Precache demo code中,当“旧内容已被清除且新内容已添加到缓存中”时,会有一行记录到控制台。它还在评论中说,现在是让用户知道新内容可用的好时机。
然而,该脚本位于服务工作者注册块中,我已将其放在def fact(x):
if x==1:
return 1
return x*fact(x-1)
n=int(input())
sum=0
k=n
#print(fact(10))
while(k!=0):
i=k%10
sum+=fact(i)
k//=10
if sum==n:
print("Yes")
else:
print("No")
文件(或我的Traceback (most recent call last):
File "4.py", line 12, in <module>
sum+=fact(i)
File "4.py", line 4, in fact
return x*fact(x-1)
File "4.py", line 4, in fact
return x*fact(x-1)
File "4.py", line 4, in fact
return x*fact(x-1)
[Previous line repeated 994 more times]
File "4.py", line 2, in fact
if x==1:
RecursionError: maximum recursion depth exceeded in comparison
文件中;我已尝试过两种方式)。但是,我希望从角度组件中收到此更新的通知,因此我可以向用户显示一个不错的通知。
这样做的正确方法是什么?我在index.html
中创建一个observable并在我的组件中导入它,但这会导致循环引用错误。
答案 0 :(得分:0)
您可以使用官方{-# LANGUAGE RankNTypes #-}
type Numeral = forall a. (a -> a) -> (a -> a)
_0 :: Numeral
_0 _ x = x
-- The numerals can be defined inductively, with base case 0 and inductive step churchSucc
-- Therefore, it helps to have a _0 constant lying around
churchSucc :: Numeral -> Numeral
churchSucc n f x = f (n f x) -- Cleaner without lambdas everywhere
sum :: Numeral -> Numeral -> Numeral
sum m n f x = m f $ n f x
mult :: Numeral -> Numeral -> Numeral
mult n m = n . m
exp :: Numeral -> Numeral -> Numeral
exp n m = m n
numerify :: Numeral -> Integer
numerify n = n (1 +) 0
toNumeral :: Integer -> Numeral
toNumeral 0 = _0
toNumeral x
| x > 0 = churchSucc $ toNumeral $ x - 1
| otherwise = error "negative argument"
包,而不是自己实现它,该包也可以与Angular CLI很好地集成。它提供了main = do out "5:" _5
out "2:" _2
out "0:" _0
out "5^0:" $ exp _5 _0
out "5 + 2:" $ sum _5 _2
out "5 * 2:" $ mult _5 _2
out "5^2:" $ exp _5 _2
out "2^5:" $ exp _2 _5
out "(0^2)^5:" $ exp (exp _0 _2) _5
where _2 = toNumeral 2
_5 = toNumeral 5
out :: String -> Numeral -> IO () -- Needed to coax the inferencer
out str n = putStrLn $ str ++ "\t" ++ (show $ numerify n)
,可在新版本可用时发出值。然后,您可以通知用户,例如展示一个小吃吧。
摘自docs:
@angular/service-worker