Skip to content

Commit 0f5dbea

Browse files
Added implementation of in-process event methods for FileReaderInProcess.
1 parent 7f0dd56 commit 0f5dbea

File tree

1 file changed

+143
-10
lines changed

1 file changed

+143
-10
lines changed

src/KristofferStrube.Blazor.FileAPI/FileReader.InProcess.cs

Lines changed: 143 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,39 +138,47 @@ public void Abort(Blob blob)
138138
/// <summary>
139139
/// Invoked when a load starts.
140140
/// </summary>
141+
[Obsolete("This will be removed in the next major release in favor of AddOnLoadStartEventListener and RemoveOnLoadStartEventListener as they are more memory safe.")]
142+
[JsonIgnore]
141143
public new Action<ProgressEventInProcess>? OnLoadStart { get; set; }
142144

143145
/// <summary>
144146
/// Invoked when the progress of a load changes which includes when it ends.
145147
/// </summary>
148+
[Obsolete("This will be removed in the next major release in favor of AddOnProgressEventListener and RemoveOnProgressEventListener as they are more memory safe.")]
146149
[JsonIgnore]
147150
public new Action<ProgressEventInProcess>? OnProgress { get; set; }
148151

149152
/// <summary>
150153
/// Invoked when a load ends successfully.
151154
/// </summary>
155+
[Obsolete("This will be removed in the next major release in favor of AddOnLoadEventListener and RemoveOnLoadEventListener as they are more memory safe.")]
152156
[JsonIgnore]
153157
public new Action<ProgressEventInProcess>? OnLoad { get; set; }
154158

155159
/// <summary>
156160
/// Invoked when a load is aborted.
157161
/// </summary>
162+
[Obsolete("This will be removed in the next major release in favor of AddOnAbortEventListener and RemoveOnAbortEventListener as they are more memory safe.")]
158163
[JsonIgnore]
159164
public new Action<ProgressEventInProcess>? OnAbort { get; set; }
160165

161166
/// <summary>
162167
/// Invoked when a load fails due to an error.
163168
/// </summary>
169+
[Obsolete("This will be removed in the next major release in favor of AddOnErrorEventListener and RemoveOnErrorEventListener as they are more memory safe.")]
164170
[JsonIgnore]
165171
public new Action<ProgressEventInProcess>? OnError { get; set; }
166172

167173
/// <summary>
168174
/// Invoked when a load finishes successfully or not.
169175
/// </summary>
176+
[Obsolete("This will be removed in the next major release in favor of AddOnLoadEndEventListener and RemoveOnLoadEndEventListener as they are more memory safe.")]
170177
[JsonIgnore]
171178
public new Action<ProgressEventInProcess>? OnLoadEnd { get; set; }
172179

173-
/// <summary>Internal method that will be removed in next major release.</summary>
180+
/// <summary>Internal method.</summary>
181+
[Obsolete("This will be removed in the next major release.")]
174182
[JSInvokable]
175183
public void InvokeOnLoadStart(IJSInProcessObjectReference jsProgressEvent)
176184
{
@@ -182,7 +190,8 @@ public void InvokeOnLoadStart(IJSInProcessObjectReference jsProgressEvent)
182190
OnLoadStart.Invoke(new ProgressEventInProcess(JSRuntime, InProcessHelper, jsProgressEvent, new() { DisposesJSReference = true }));
183191
}
184192

185-
/// <summary>Internal method that will be removed in next major release.</summary>
193+
/// <summary>Internal method.</summary>
194+
[Obsolete("This will be removed in the next major release.")]
186195
[JSInvokable]
187196
public void InvokeOnProgress(IJSInProcessObjectReference jsProgressEvent)
188197
{
@@ -194,7 +203,8 @@ public void InvokeOnProgress(IJSInProcessObjectReference jsProgressEvent)
194203
OnProgress.Invoke(new ProgressEventInProcess(JSRuntime, InProcessHelper, jsProgressEvent, new() { DisposesJSReference = true }));
195204
}
196205

197-
/// <summary>Internal method that will be removed in next major release.</summary>
206+
/// <summary>Internal method.</summary>
207+
[Obsolete("This will be removed in the next major release.")]
198208
[JSInvokable]
199209
public void InvokeOnLoad(IJSInProcessObjectReference jsProgressEvent)
200210
{
@@ -206,7 +216,8 @@ public void InvokeOnLoad(IJSInProcessObjectReference jsProgressEvent)
206216
OnLoad.Invoke(new ProgressEventInProcess(JSRuntime, InProcessHelper, jsProgressEvent, new() { DisposesJSReference = true }));
207217
}
208218

209-
/// <summary>Internal method that will be removed in next major release.</summary>
219+
/// <summary>Internal method.</summary>
220+
[Obsolete("This will be removed in the next major release.")]
210221
[JSInvokable]
211222
public void InvokeOnAbort(IJSInProcessObjectReference jsProgressEvent)
212223
{
@@ -218,7 +229,8 @@ public void InvokeOnAbort(IJSInProcessObjectReference jsProgressEvent)
218229
OnAbort.Invoke(new ProgressEventInProcess(JSRuntime, InProcessHelper, jsProgressEvent, new() { DisposesJSReference = true }));
219230
}
220231

221-
/// <summary>Internal method that will be removed in next major release.</summary>
232+
/// <summary>Internal method.</summary>
233+
[Obsolete("This will be removed in the next major release.")]
222234
[JSInvokable]
223235
public void InvokeOnError(IJSInProcessObjectReference jsProgressEvent)
224236
{
@@ -230,7 +242,8 @@ public void InvokeOnError(IJSInProcessObjectReference jsProgressEvent)
230242
OnError.Invoke(new ProgressEventInProcess(JSRuntime, InProcessHelper, jsProgressEvent, new() { DisposesJSReference = true }));
231243
}
232244

233-
/// <summary>Internal method that will be removed in next major release.</summary>
245+
/// <summary>Internal method.</summary>
246+
[Obsolete("This will be removed in the next major release.")]
234247
[JSInvokable]
235248
public void InvokeOnLoadEnd(IJSInProcessObjectReference jsProgressEvent)
236249
{
@@ -246,28 +259,148 @@ public void InvokeOnLoadEnd(IJSInProcessObjectReference jsProgressEvent)
246259
public void AddEventListener<TInProcessEvent, TEvent>(string type, EventListenerInProcess<TInProcessEvent, TEvent>? callback, AddEventListenerOptions? options = null)
247260
where TEvent : Event, IJSCreatable<TEvent> where TInProcessEvent : IJSInProcessCreatable<TInProcessEvent, TEvent>
248261
{
249-
this.AddEventListener(InProcessHelper, type, callback, options);
262+
JSReference.InvokeVoid("addEventListener", type, callback?.JSReference, options);
250263
}
251264

252265
/// <inheritdoc/>
253266
public void AddEventListener<TInProcessEvent, TEvent>(EventListenerInProcess<TInProcessEvent, TEvent>? callback, AddEventListenerOptions? options = null)
254267
where TEvent : Event, IJSCreatable<TEvent> where TInProcessEvent : IJSInProcessCreatable<TInProcessEvent, TEvent>
255268
{
256-
this.AddEventListener(InProcessHelper, callback, options);
269+
JSReference.InvokeVoid("addEventListener", typeof(TEvent).Name, callback?.JSReference, options);
257270
}
258271

259272
/// <inheritdoc/>
260273
public void RemoveEventListener<TInProcessEvent, TEvent>(string type, EventListenerInProcess<TInProcessEvent, TEvent>? callback, EventListenerOptions? options = null)
261274
where TEvent : Event, IJSCreatable<TEvent> where TInProcessEvent : IJSInProcessCreatable<TInProcessEvent, TEvent>
262275
{
263-
this.RemoveEventListener(InProcessHelper, type, callback, options);
276+
JSReference.InvokeVoid("removeEventListener", type, callback?.JSReference, options);
264277
}
265278

266279
/// <inheritdoc/>
267280
public void RemoveEventListener<TInProcessEvent, TEvent>(EventListenerInProcess<TInProcessEvent, TEvent>? callback, EventListenerOptions? options = null)
268281
where TEvent : Event, IJSCreatable<TEvent> where TInProcessEvent : IJSInProcessCreatable<TInProcessEvent, TEvent>
269282
{
270-
this.RemoveEventListener(InProcessHelper, callback, options);
283+
JSReference.InvokeVoid("removeEventListener", typeof(TEvent).Name, callback?.JSReference, options);
284+
}
285+
286+
/// <summary>
287+
/// Adds an <see cref="EventListenerInProcess{TInProcessEvent, TEvent}"/> for when a load is started.
288+
/// </summary>
289+
/// <param name="callback">Callback that will be invoked when the event is dispatched.</param>
290+
/// <param name="options"><inheritdoc cref="AddEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, AddEventListenerOptions?)" path="/param[@name='options']"/></param>
291+
public void AddOnLoadStartEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, AddEventListenerOptions? options = null)
292+
{
293+
AddEventListener("loadstart", callback, options);
294+
}
295+
296+
/// <summary>
297+
/// Removes the event listener from the event listener list if it has been parsed to <see cref="AddOnLoadStartEventListener"/> previously.
298+
/// </summary>
299+
/// <param name="callback">The callback <see cref="EventListener{TEvent}"/> that you want to stop listening to events.</param>
300+
/// <param name="options"><inheritdoc cref="RemoveEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, EventListenerOptions?)" path="/param[@name='options']"/></param>
301+
public void RemoveOnLoadStartEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, EventListenerOptions? options = null)
302+
{
303+
RemoveEventListener("loadstart", callback, options);
304+
}
305+
306+
/// <summary>
307+
/// Adds an <see cref="EventListenerInProcess{TInProcessEvent, TEvent}"/> for when the progress of a load changes which includes when it ends.
308+
/// </summary>
309+
/// <param name="callback">Callback that will be invoked when the event is dispatched.</param>
310+
/// <param name="options"><inheritdoc cref="AddEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, AddEventListenerOptions?)" path="/param[@name='options']"/></param>
311+
public void AddOnProgressEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, AddEventListenerOptions? options = null)
312+
{
313+
AddEventListener("progress", callback, options);
314+
}
315+
316+
/// <summary>
317+
/// Removes the event listener from the event listener list if it has been parsed to <see cref="AddOnProgressEventListener"/> previously.
318+
/// </summary>
319+
/// <param name="callback">The callback <see cref="EventListener{TEvent}"/> that you want to stop listening to events.</param>
320+
/// <param name="options"><inheritdoc cref="RemoveEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, EventListenerOptions?)" path="/param[@name='options']"/></param>
321+
public void RemoveOnProgressEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, EventListenerOptions? options = null)
322+
{
323+
RemoveEventListener("progress", callback, options);
324+
}
325+
326+
/// <summary>
327+
/// Adds an <see cref="EventListenerInProcess{TInProcessEvent, TEvent}"/> for when a load ends successfully.
328+
/// </summary>
329+
/// <param name="callback">Callback that will be invoked when the event is dispatched.</param>
330+
/// <param name="options"><inheritdoc cref="AddEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, AddEventListenerOptions?)" path="/param[@name='options']"/></param>
331+
public void AddOnLoadEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, AddEventListenerOptions? options = null)
332+
{
333+
AddEventListener("load", callback, options);
334+
}
335+
336+
/// <summary>
337+
/// Removes the event listener from the event listener list if it has been parsed to <see cref="AddOnLoadEventListener"/> previously.
338+
/// </summary>
339+
/// <param name="callback">The callback <see cref="EventListener{TEvent}"/> that you want to stop listening to events.</param>
340+
/// <param name="options"><inheritdoc cref="RemoveEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, EventListenerOptions?)" path="/param[@name='options']"/></param>
341+
public void RemoveOnLoadEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, EventListenerOptions? options = null)
342+
{
343+
RemoveEventListener("load", callback, options);
344+
}
345+
346+
/// <summary>
347+
/// Adds an <see cref="EventListenerInProcess{TInProcessEvent, TEvent}"/> for when a load is aborted.
348+
/// </summary>
349+
/// <param name="callback">Callback that will be invoked when the event is dispatched.</param>
350+
/// <param name="options"><inheritdoc cref="AddEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, AddEventListenerOptions?)" path="/param[@name='options']"/></param>
351+
public void AddOnAbortEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, AddEventListenerOptions? options = null)
352+
{
353+
AddEventListener("abort", callback, options);
354+
}
355+
356+
/// <summary>
357+
/// Removes the event listener from the event listener list if it has been parsed to <see cref="AddOnAbortEventListener"/> previously.
358+
/// </summary>
359+
/// <param name="callback">The callback <see cref="EventListener{TEvent}"/> that you want to stop listening to events.</param>
360+
/// <param name="options"><inheritdoc cref="RemoveEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, EventListenerOptions?)" path="/param[@name='options']"/></param>
361+
public void RemoveOnAbortEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, EventListenerOptions? options = null)
362+
{
363+
RemoveEventListener("abort", callback, options);
364+
}
365+
366+
/// <summary>
367+
/// Adds an <see cref="EventListenerInProcess{TInProcessEvent, TEvent}"/> for when a load fails due to an error.
368+
/// </summary>
369+
/// <param name="callback">Callback that will be invoked when the event is dispatched.</param>
370+
/// <param name="options"><inheritdoc cref="AddEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, AddEventListenerOptions?)" path="/param[@name='options']"/></param>
371+
public void AddOnErrorEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, AddEventListenerOptions? options = null)
372+
{
373+
AddEventListener("error", callback, options);
374+
}
375+
376+
/// <summary>
377+
/// Removes the event listener from the event listener list if it has been parsed to <see cref="AddOnErrorEventListener"/> previously.
378+
/// </summary>
379+
/// <param name="callback">The callback <see cref="EventListener{TEvent}"/> that you want to stop listening to events.</param>
380+
/// <param name="options"><inheritdoc cref="RemoveEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, EventListenerOptions?)" path="/param[@name='options']"/></param>
381+
public void RemoveOnErrorEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, EventListenerOptions? options = null)
382+
{
383+
RemoveEventListener("error", callback, options);
384+
}
385+
386+
/// <summary>
387+
/// Adds an <see cref="EventListenerInProcess{TInProcessEvent, TEvent}"/> for when a load finishes successfully or not.
388+
/// </summary>
389+
/// <param name="callback">Callback that will be invoked when the event is dispatched.</param>
390+
/// <param name="options"><inheritdoc cref="AddEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, AddEventListenerOptions?)" path="/param[@name='options']"/></param>
391+
public void AddOnLoadEndEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, AddEventListenerOptions? options = null)
392+
{
393+
AddEventListener("loadend", callback, options);
394+
}
395+
396+
/// <summary>
397+
/// Removes the event listener from the event listener list if it has been parsed to <see cref="AddOnLoadEndEventListener"/> previously.
398+
/// </summary>
399+
/// <param name="callback">The callback <see cref="EventListener{TEvent}"/> that you want to stop listening to events.</param>
400+
/// <param name="options"><inheritdoc cref="RemoveEventListener{TInProcessEvent, TEvent}(string, EventListenerInProcess{TInProcessEvent, TEvent}?, EventListenerOptions?)" path="/param[@name='options']"/></param>
401+
public void RemoveOnLoadEndEventListener(EventListenerInProcess<ProgressEventInProcess, ProgressEvent> callback, EventListenerOptions? options = null)
402+
{
403+
RemoveEventListener("loadend", callback, options);
271404
}
272405

273406
/// <inheritdoc/>

0 commit comments

Comments
 (0)