Skip to content

Commit d729ef2

Browse files
authored
Refactor Subscriber to hold an internal observer instead of individual algorithms (#196)
1 parent 9bd160f commit d729ef2

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

spec.bs

+17-27
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,8 @@ interface Subscriber {
177177
};
178178
</xmp>
179179

180-
Each {{Subscriber}} has a <dfn for=Subscriber>next algorithm</dfn>, which is a [=internal
181-
observer/next steps=].
182-
183-
Each {{Subscriber}} has a <dfn for=Subscriber>error algorithm</dfn>, which is an [=internal
184-
observer/error steps=].
185-
186-
Each {{Subscriber}} has a <dfn for=Subscriber>complete algorithm</dfn>, which is a [=internal
187-
observer/complete steps=].
180+
Each {{Subscriber}} has a <dfn for=Subscriber>internal observer</dfn>, which is an [=internal
181+
observer=].
188182

189183
Each {{Subscriber}} has a <dfn for=Subscriber>teardown callbacks</dfn>, which is a [=list=] of
190184
{{VoidFunction}}s, initially empty.
@@ -211,18 +205,20 @@ The <dfn attribute for=Subscriber><code>signal</code></dfn> getter steps are to
211205
1. If [=this=]'s [=relevant global object=] is a {{Window}} object, and its [=associated
212206
Document=] is not [=Document/fully active=], then return.
213207

214-
1. Run [=this=]'s [=Subscriber/next algorithm=] given |value|.
208+
1. Run [=this=]'s [=Subscriber/internal observer=]'s [=internal observer/next steps=] given
209+
|value|.
215210

216211
[=Assert=]: No <a spec=webidl lt="an exception was thrown">exception was thrown</a>.
217212

218213
<div class=note>
219-
<p>Note: No exception can be thrown here because in the case where [=Subscriber/next
220-
algorithm=] is just a wrapper around a script-provided callback, the <a
221-
href=#process-observer>process observer</a> steps take care to wrap these callbacks in
222-
logic that, when invoking them, catches any exceptions, and reports them to the global.</p>
223-
224-
<p>When the [=Subscriber/next algorithm=] is a spec algorithm, those steps take care to not
225-
throw any exceptions outside of itself, to appease this assert.</p>
214+
<p>Note: No exception can be thrown here because in the case where the
215+
[=Subscriber/internal observer=]'s [=internal observer/next steps=] is just a wrapper
216+
around a script-provided callback, the <a href=#process-observer>process observer</a> steps
217+
take care to wrap these callbacks in logic that, when invoking them, catches any
218+
exceptions, and reports them to the global.</p>
219+
220+
<p>When the [=internal observer/next steps=] is a spec algorithm, those steps take care to
221+
not throw any exceptions outside of itself, to appease this assert.</p>
226222
</div>
227223
</div>
228224

@@ -236,7 +232,8 @@ The <dfn attribute for=Subscriber><code>signal</code></dfn> getter steps are to
236232

237233
1. [=close a subscription|Close=] [=this=].
238234

239-
1. Run [=this=]'s [=Subscriber/error algorithm=] given |error|.
235+
1. Run [=this=]'s [=Subscriber/internal observer=]'s [=internal observer/error steps=] given
236+
|error|.
240237

241238
[=Assert=]: No <a spec=webidl lt="an exception was thrown">exception was thrown</a>.
242239

@@ -253,7 +250,7 @@ The <dfn attribute for=Subscriber><code>signal</code></dfn> getter steps are to
253250

254251
1. [=close a subscription|Close=] [=this=].
255252

256-
1. Run [=this=]'s [=Subscriber/complete algorithm=].
253+
1. Run [=this=]'s [=Subscriber/internal observer=]'s [=internal observer/complete steps=].
257254

258255
[=Assert=]: No <a spec=webidl lt="an exception was thrown">exception was thrown</a>.
259256

@@ -735,16 +732,9 @@ An <dfn>internal observer</dfn> is a [=struct=] with the following [=struct/item
735732
error algorithm=], or an algorithm that [=invokes=] the provided {{SubscriptionObserver/error}}
736733
[=callback function=].
737734

738-
1. Let |subscriber| be a [=new=] {{Subscriber}}, initialized as:
739-
740-
: [=Subscriber/next algorithm=]
741-
:: |internal observer|'s [=internal observer/next steps=]
742-
743-
: [=Subscriber/error algorithm=]
744-
:: |internal observer|'s [=internal observer/error steps=]
735+
1. Let |subscriber| be a [=new=] {{Subscriber}}.
745736

746-
: [=Subscriber/complete algorithm=]
747-
:: |internal observer|'s [=internal observer/complete steps=]
737+
1. Set |subscriber|'s [=Subscriber/internal observer=] to |internal observer|.
748738

749739
1. If |options|'s {{SubscribeOptions/signal}} [=map/exists=], then:
750740

0 commit comments

Comments
 (0)