How to use the mwp-router/lib/util.getMatchedQueries function in mwp-router

To help you get started, we’ve selected a few mwp-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meetup / meetup-web-platform / packages / mwp-api-state / src / sync / index.js View on Github external
const { payload: location } = action;
	const state = store.getState();
	const { referrer = {} } = state.routing;
	// inject request metadata from context, including `store.getState()`
	const requestMetadata = {
		referrer: referrer.pathname || state.config.entryPath || '',
		logout: location.pathname.endsWith('logout'), // assume logout route ends with logout - not currently implemented in any app
		clickTracking: true, // clicks should be tracked with this request
		retainRefs: [],
	};
	const cacheAction = requestMetadata.logout && { type: 'CACHE_CLEAR' };

	const previousQueries = referrer.pathname
		? getMatchedQueries(referrer, state)(findMatches(referrer))
		: [];
	const newQueries = getMatchedQueries(location, state)(findMatches(location));
	if (newQueries.filter(q => q).length === 0) {
		// no valid queries - jump straight to 'complete'
		return [api.complete([])];
	}
	// perform a fast comparison of previous route's serialized queries
	// with the new route's serialized queries. All state refs for
	// _shared_ queries should be retained
	const serializedNew = newQueries.map(JSON.stringify);
	const serializedPrev = previousQueries.map(JSON.stringify);
	const sharedRefs = serializedPrev
		.filter(qJSON => serializedNew.includes(qJSON))
		.map(JSON.parse)
		.map(q => q.ref);
	requestMetadata.retainRefs = sharedRefs;

	return Promise.resolve(
github meetup / meetup-web-platform / packages / mwp-api-state / src / sync / index.js View on Github external
const state = store.getState();
	const { referrer = {} } = state.routing;
	// inject request metadata from context, including `store.getState()`
	const requestMetadata = {
		referrer: referrer.pathname || state.config.entryPath || '',
		logout: location.pathname.endsWith('logout'), // assume logout route ends with logout - not currently implemented in any app
		clickTracking: state.clickTracking,
		retainRefs: [],
	};
	const cacheAction = requestMetadata.logout && { type: 'CACHE_CLEAR' };

	const resolvePrevQueries = referrer.pathname
		? resolveRoutes(referrer).then(getMatchedQueries(referrer))
		: Promise.resolve([]);
	const resolveNewQueries = resolveRoutes(location).then(
		getMatchedQueries(location)
	);

	return Promise.all([resolveNewQueries, resolvePrevQueries]).then(
		([newQueries, previousQueries]) => {
			if (newQueries.filter(q => q).length === 0) {
				// no valid queries - jump straight to 'complete'
				return [api.complete([])];
			}
			// perform a fast comparison of previous route's serialized queries
			// with the new route's serialized queries. All state refs for
			// _shared_ queries should be retained
			const serializedNew = newQueries.map(JSON.stringify);
			const serializedPrev = previousQueries.map(JSON.stringify);
			const sharedRefs = serializedPrev
				.filter(qJSON => serializedNew.includes(qJSON))
				.map(JSON.parse)
github meetup / meetup-web-platform / packages / mwp-api-state / src / sync / index.js View on Github external
return IGNORE_ACTION;
	}
	const { payload: location } = action;
	const state = store.getState();
	const { referrer = {} } = state.routing;
	// inject request metadata from context, including `store.getState()`
	const requestMetadata = {
		referrer: referrer.pathname || state.config.entryPath || '',
		logout: location.pathname.endsWith('logout'), // assume logout route ends with logout - not currently implemented in any app
		clickTracking: true, // clicks should be tracked with this request
		retainRefs: [],
	};
	const cacheAction = requestMetadata.logout && { type: 'CACHE_CLEAR' };

	const previousQueries = referrer.pathname
		? getMatchedQueries(referrer, state)(findMatches(referrer))
		: [];
	const newQueries = getMatchedQueries(location, state)(findMatches(location));
	if (newQueries.filter(q => q).length === 0) {
		// no valid queries - jump straight to 'complete'
		return [api.complete([])];
	}
	// perform a fast comparison of previous route's serialized queries
	// with the new route's serialized queries. All state refs for
	// _shared_ queries should be retained
	const serializedNew = newQueries.map(JSON.stringify);
	const serializedPrev = previousQueries.map(JSON.stringify);
	const sharedRefs = serializedPrev
		.filter(qJSON => serializedNew.includes(qJSON))
		.map(JSON.parse)
		.map(q => q.ref);
	requestMetadata.retainRefs = sharedRefs;
github meetup / meetup-web-platform / packages / mwp-api-state / src / sync / index.js View on Github external
return Promise.resolve([]);
	}
	const { payload: location } = action;
	const state = store.getState();
	const { referrer = {} } = state.routing;
	// inject request metadata from context, including `store.getState()`
	const requestMetadata = {
		referrer: referrer.pathname || state.config.entryPath || '',
		logout: location.pathname.endsWith('logout'), // assume logout route ends with logout - not currently implemented in any app
		clickTracking: state.clickTracking,
		retainRefs: [],
	};
	const cacheAction = requestMetadata.logout && { type: 'CACHE_CLEAR' };

	const resolvePrevQueries = referrer.pathname
		? resolveRoutes(referrer).then(getMatchedQueries(referrer))
		: Promise.resolve([]);
	const resolveNewQueries = resolveRoutes(location).then(
		getMatchedQueries(location)
	);

	return Promise.all([resolveNewQueries, resolvePrevQueries]).then(
		([newQueries, previousQueries]) => {
			if (newQueries.filter(q => q).length === 0) {
				// no valid queries - jump straight to 'complete'
				return [api.complete([])];
			}
			// perform a fast comparison of previous route's serialized queries
			// with the new route's serialized queries. All state refs for
			// _shared_ queries should be retained
			const serializedNew = newQueries.map(JSON.stringify);
			const serializedPrev = previousQueries.map(JSON.stringify);