@tanstack/query-core
Advanced tools
Comparing version 5.0.0-alpha.59 to 5.0.0-alpha.61
@@ -35,3 +35,3 @@ import { notifyManager } from './notifyManager.js'; | ||
addObserver(observer) { | ||
if (this.#observers.indexOf(observer) === -1) { | ||
if (!this.#observers.includes(observer)) { | ||
this.#observers.push(observer); | ||
@@ -38,0 +38,0 @@ |
import { Subscribable } from './subscribable.js'; | ||
import { isServer } from './utils.js'; | ||
const onlineEvents = ['online', 'offline']; | ||
class OnlineManager extends Subscribable { | ||
@@ -16,8 +17,10 @@ #online; | ||
// Listen to online | ||
window.addEventListener('online', listener, false); | ||
window.addEventListener('offline', listener, false); | ||
onlineEvents.forEach(event => { | ||
window.addEventListener(event, listener, false); | ||
}); | ||
return () => { | ||
// Be sure to unsubscribe if a new handler is set | ||
window.removeEventListener('online', listener); | ||
window.removeEventListener('offline', listener); | ||
onlineEvents.forEach(event => { | ||
window.removeEventListener(event, listener); | ||
}); | ||
}; | ||
@@ -24,0 +27,0 @@ } |
@@ -7,3 +7,3 @@ import { notifyManager } from './notifyManager.js'; | ||
function difference(array1, array2) { | ||
return array1.filter(x => array2.indexOf(x) === -1); | ||
return array1.filter(x => !array2.includes(x)); | ||
} | ||
@@ -10,0 +10,0 @@ function replaceAt(array, index, value) { |
@@ -112,3 +112,3 @@ import { replaceData, noop, timeUntilStale } from './utils.js'; | ||
addObserver(observer) { | ||
if (this.#observers.indexOf(observer) === -1) { | ||
if (!this.#observers.includes(observer)) { | ||
this.#observers.push(observer); | ||
@@ -126,3 +126,3 @@ | ||
removeObserver(observer) { | ||
if (this.#observers.indexOf(observer) !== -1) { | ||
if (this.#observers.includes(observer)) { | ||
this.#observers = this.#observers.filter(x => x !== observer); | ||
@@ -129,0 +129,0 @@ if (!this.#observers.length) { |
@@ -31,2 +31,3 @@ import type { DefaultedQueryObserverOptions, DefaultError, QueryKey, QueryObserverOptions, QueryObserverResult, RefetchOptions } from './types'; | ||
protected createResult(query: Query<TQueryFnData, TError, TQueryData, TQueryKey>, options: QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>): QueryObserverResult<TData, TError>; | ||
updateResult(notifyOptions?: NotifyOptions): void; | ||
onQueryUpdate(): void; | ||
@@ -33,0 +34,0 @@ } |
@@ -89,3 +89,3 @@ import { shallowEqualObjects, noop, isServer, isValidTimeout, timeUntilStale, replaceData } from './utils.js'; | ||
// Update result | ||
this.#updateResult(notifyOptions); | ||
this.updateResult(notifyOptions); | ||
@@ -145,3 +145,3 @@ // Update stale interval if needed | ||
}).then(() => { | ||
this.#updateResult(); | ||
this.updateResult(); | ||
return this.#currentResult; | ||
@@ -173,3 +173,3 @@ }); | ||
if (!this.#currentResult.isStale) { | ||
this.#updateResult(); | ||
this.updateResult(); | ||
} | ||
@@ -329,3 +329,3 @@ }, timeout); | ||
} | ||
#updateResult(notifyOptions) { | ||
updateResult(notifyOptions) { | ||
const prevResult = this.#currentResult; | ||
@@ -389,3 +389,3 @@ const nextResult = this.createResult(this.#currentQuery, this.options); | ||
onQueryUpdate() { | ||
this.#updateResult(); | ||
this.updateResult(); | ||
if (this.hasListeners()) { | ||
@@ -392,0 +392,0 @@ this.#updateTimers(); |
{ | ||
"name": "@tanstack/query-core", | ||
"version": "5.0.0-alpha.59", | ||
"version": "5.0.0-alpha.61", | ||
"description": "The framework agnostic core that powers TanStack Query", | ||
@@ -5,0 +5,0 @@ "author": "tannerlinsley", |
@@ -122,3 +122,3 @@ import type { | ||
addObserver(observer: MutationObserver<any, any, any, any>): void { | ||
if (this.#observers.indexOf(observer) === -1) { | ||
if (!this.#observers.includes(observer)) { | ||
this.#observers.push(observer) | ||
@@ -125,0 +125,0 @@ |
@@ -8,2 +8,4 @@ import { Subscribable } from './subscribable' | ||
const onlineEvents = ['online', 'offline'] as const | ||
export class OnlineManager extends Subscribable { | ||
@@ -23,9 +25,11 @@ #online?: boolean | ||
// Listen to online | ||
window.addEventListener('online', listener, false) | ||
window.addEventListener('offline', listener, false) | ||
onlineEvents.forEach((event) => { | ||
window.addEventListener(event, listener, false) | ||
}) | ||
return () => { | ||
// Be sure to unsubscribe if a new handler is set | ||
window.removeEventListener('online', listener) | ||
window.removeEventListener('offline', listener) | ||
onlineEvents.forEach((event) => { | ||
window.removeEventListener(event, listener) | ||
}) | ||
} | ||
@@ -32,0 +36,0 @@ } |
@@ -14,3 +14,3 @@ import { notifyManager } from './notifyManager' | ||
function difference<T>(array1: T[], array2: T[]): T[] { | ||
return array1.filter((x) => array2.indexOf(x) === -1) | ||
return array1.filter((x) => !array2.includes(x)) | ||
} | ||
@@ -17,0 +17,0 @@ |
@@ -284,3 +284,3 @@ import { noop, replaceData, timeUntilStale } from './utils' | ||
addObserver(observer: QueryObserver<any, any, any, any, any>): void { | ||
if (this.#observers.indexOf(observer) === -1) { | ||
if (!this.#observers.includes(observer)) { | ||
this.#observers.push(observer) | ||
@@ -296,3 +296,3 @@ | ||
removeObserver(observer: QueryObserver<any, any, any, any, any>): void { | ||
if (this.#observers.indexOf(observer) !== -1) { | ||
if (this.#observers.includes(observer)) { | ||
this.#observers = this.#observers.filter((x) => x !== observer) | ||
@@ -299,0 +299,0 @@ |
@@ -194,3 +194,3 @@ import type { | ||
// Update result | ||
this.#updateResult(notifyOptions) | ||
this.updateResult(notifyOptions) | ||
@@ -295,3 +295,3 @@ // Update stale interval if needed | ||
}).then(() => { | ||
this.#updateResult() | ||
this.updateResult() | ||
return this.#currentResult | ||
@@ -342,3 +342,3 @@ }) | ||
if (!this.#currentResult.isStale) { | ||
this.#updateResult() | ||
this.updateResult() | ||
} | ||
@@ -567,3 +567,3 @@ }, timeout) | ||
#updateResult(notifyOptions?: NotifyOptions): void { | ||
updateResult(notifyOptions?: NotifyOptions): void { | ||
const prevResult = this.#currentResult as | ||
@@ -644,3 +644,3 @@ | QueryObserverResult<TData, TError> | ||
onQueryUpdate(): void { | ||
this.#updateResult() | ||
this.updateResult() | ||
@@ -647,0 +647,0 @@ if (this.hasListeners()) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1055123
16708