How to use the @dojo/framework/stores/state/operations.replace function in @dojo/framework

To help you get started, we’ve selected a few @dojo/framework 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 dojo / examples / realworld / src / processes / tagProcesses.ts View on Github external
const getTagsCommand = commandFactory(async ({ path }) => {
	const response = await fetch(`${baseUrl}/tags`);
	const json = await response.json();

	return [replace(path("tags"), json.tags)];
});
github gothinkster / dojo-realworld-example-app / src / processes / profileProcesses.ts View on Github external
async ({ get, path, payload: { username } }) => {
		const token = get(path("session", "token"));
		const response = await fetch(`${baseUrl}/profiles/${username}`, {
			headers: getHeaders(token)
		});
		const json = await response.json();

		return [
			replace(path("profile", "user", "username"), json.profile.username),
			replace(path("profile", "user", "image"), json.profile.image),
			replace(path("profile", "user", "bio"), json.profile.bio),
			replace(path("profile", "user", "following"), json.profile.following),
			replace(path("profile", "user", "isLoading"), false),
			replace(path("profile", "user", "isLoaded"), true)
		];
	}
);
github dojo / examples / realworld / src / processes / articleProcesses.ts View on Github external
const deleteArticleCommand = commandFactory(async ({ get, path, payload: { slug } }) => {
	const token = get(path("session", "token"));
	await fetch(`${baseUrl}/articles/${slug}`, {
		method: "delete",
		headers: getHeaders(token)
	});
	return [replace(path("routing", "outlet"), "home")];
});
github dojo / widgets / src / grid / processes.ts View on Github external
const filterOptions = get(path(id, 'meta', 'filter'));
		let result: FetcherResult[];
		try {
			const options = {
				sort: { columnId, direction },
				filter: filterOptions
			};
			const previousPage = fetcher(page - 1, pageSize, options);
			const currentPage = fetcher(page, pageSize, options);
			result = await Promise.all([previousPage, currentPage]);
		} catch (err) {
			return [];
		}

		return [
			replace(path(id, 'data', 'pages', `page-${page - 1}`), result[0].data),
			replace(path(id, 'data', 'pages', `page-${page}`), result[1].data),
			replace(path(id, 'meta', 'sort', 'columnId'), columnId),
			replace(path(id, 'meta', 'sort', 'direction'), direction),
			replace(path(id, 'meta', 'total'), result[1].meta.total),
			replace(path(id, 'meta', 'page'), page),
			replace(path(id, 'meta', 'isSorting'), false)
		];
	}
);
github gothinkster / dojo-realworld-example-app / src / processes / editorProcesses.ts View on Github external
const bodyInputCommand = commandFactory(({ path, payload: { body } }) => {
	return [replace(path("editor", "body"), body)];
});
github dojo / widgets / src / grid / processes.ts View on Github external
async ({ at, path, get, payload: { id, updater, columnId, value, page, rowNumber } }) => {
		const item = get(at(path(id, 'data', 'pages', `page-${page}`), rowNumber));
		try {
			await updater(item);
		} catch (err) {
			const previousItem = get(path(id, 'meta', 'editedRow', 'item'));
			return [
				replace(at(path(id, 'data', 'pages', `page-${page}`), rowNumber), previousItem)
			];
		}

		return [replace(path(id, 'meta', 'editedRow'), undefined)];
	}
);
github dojo / examples / realworld / src / processes / settingsProcesses.ts View on Github external
const emailInputCommand = commandFactory(({ payload: { email }, path }) => {
	return [replace(path('settings', 'email'), email)];
});
github dojo / examples / realworld / src / processes / loginProcesses.ts View on Github external
const loginEmailInputCommand = commandFactory(({ path, payload: { email } }) => {
	return [replace(path('login', 'email'), email)];
});
github gothinkster / dojo-realworld-example-app / src / processes / feedProcesses.ts View on Github external
url = `${baseUrl}/articles/feed?`;
				break;
			case "tag":
				url = `${baseUrl}/articles?tag=${filter}&`;
				break;
			default:
				url = `${baseUrl}/articles/?`;
				break;
		}

		const response = await fetch(`${url}limit=10&offset=${offset}`, { headers: getHeaders(token) });
		const json = await response.json();
		return [
			replace(path("feed", "items"), json.articles),
			replace(path("feed", "total"), json.articlesCount),
			replace(path("feed", "offset"), offset),
			replace(path("feed", "page"), page),
			replace(path("feed", "category"), type),
			replace(path("feed", "filter"), filter),
			replace(path("feed", "isLoading"), false),
			replace(path("feed", "isLoaded"), true)
		];
	}
);
github dojo / examples / realworld / src / processes / articleProcesses.ts View on Github external
const requestPayload = {
		comment: {
			body: newComment
		}
	};
	const response = await fetch(`${baseUrl}/articles/${slug}/comments`, {
		method: "post",
		headers: getHeaders(token),
		body: JSON.stringify(requestPayload)
	});
	const json = await response.json();
	const comments = get(path("article", slug, "comments"));

	return [
		replace(path("article", slug, "comments"), [...comments, json.comment]),
		replace(path("article", slug, "newComment"), "")
	];
});