aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/serviceworker/statechange_event/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ko/web/api/serviceworker/statechange_event/index.html')
-rw-r--r--files/ko/web/api/serviceworker/statechange_event/index.html73
1 files changed, 73 insertions, 0 deletions
diff --git a/files/ko/web/api/serviceworker/statechange_event/index.html b/files/ko/web/api/serviceworker/statechange_event/index.html
new file mode 100644
index 0000000000..aebeda7895
--- /dev/null
+++ b/files/ko/web/api/serviceworker/statechange_event/index.html
@@ -0,0 +1,73 @@
+---
+title: ServiceWorker.onstatechange
+slug: Web/API/ServiceWorker/statechange_event
+translation_of: Web/API/ServiceWorker/onstatechange
+original_slug: Web/API/ServiceWorker/onstatechange
+---
+<div>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</div>
+
+<p><code>statechange</code> 타입의 이벤트가 발생될 때마다 호출되는 {{domxref("EventListener")}} 속성. 기본적으로 {{domxref("ServiceWorker.state")}}가 변경되는 시점에 발생한다.</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox">ServiceWorker.onstatechange = function(statechangeevent) { ... }
+ServiceWorker.addEventListener('statechange', function(statechangeevent) { ... } )</pre>
+
+<h2 id="Examples">Examples</h2>
+
+<p>이 코드 조각은 <a href="https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/registration-events/index.html">service worker registration-events sample</a> (<a href="https://googlechrome.github.io/samples/service-worker/registration-events/">live demo</a>) 으로부터 가져온 것이다. 이 코드는 {{domxref("ServiceWorker.state")}}의 모든 변경 사항을 수신하고 그 값을 반환한다.</p>
+
+<pre class="brush: js">var serviceWorker;
+if (registration.installing) {
+ serviceWorker = registration.installing;
+ document.querySelector('#kind').textContent = 'installing';
+} else if (registration.waiting) {
+ serviceWorker = registration.waiting;
+ document.querySelector('#kind').textContent = 'waiting';
+} else if (registration.active) {
+ serviceWorker = registration.active;
+ document.querySelector('#kind').textContent = 'active';
+}
+
+if (serviceWorker) {
+ logState(serviceWorker.state);
+ serviceWorker.addEventListener('statechange', function(e) {
+ logState(e.target.state);
+ });
+}</pre>
+
+<p><code>statechange</code> 가 발생할 때, 서비스워커의 참조들이 변화할 수 있으므로 주의하라. 예시:</p>
+
+<pre class="brush: js">navigator.serviceWorker.register(..).then(function(swr) {
+ swr.installing.state == "installing"
+ swr.installing.onstatechange = function() {
+ swr.installing == null;
+ // 이 시점에서, swr.waiting 또는 swr.active는 true일 것이다. 이것은 statechange 이벤트가 대기 상태이기 때문이며,
+ // 그동안 잠재 상태의 워커가 waiting 상태가 될 수도 있으며 가능한 경우에는 즉시 activated 될 것이다.
+ }
+})</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Service Workers', '#service-worker-onstatechange-attribute', 'ServiceWorker.onstatechange')}}</td>
+ <td>{{Spec2('Service Workers')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<div>
+
+
+<p>{{Compat("api.ServiceWorker.onstatechange")}}</p>
+</div>