Skip to content

Instantly share code, notes, and snippets.

@epelz

epelz/task_mutations.ts Secret

Last active Mar 14, 2016
Embed
What would you like to do?
Example: Mutation helper
export function heartTask(attr: {
datastore: DatastoreService;
// Thin interfaces for the User/Task model which utilize TypeScript's
// structural typing, but the type aliases are omitted for brevity.
user: UserBase;
task: TaskBase;
}) {
attr.datastore.runInBatch(() => {
// 1. Optimistically create the object representing the heart.
var heartRequest = new HeartCreateRequest({
target: attr.task.dbObjectId(),
user: attr.user.dbObjectId()
});
var heartId = attr.datastore.createDbObject(heartRequest);
// 2. Send server request to update the database.
attr.services.datastore.requestServerChange(
“post”, /task_heart”, {
// server will create an identical object with the same ID.
global_id: heartId,
task: task.dbObjectId(),
user: attr.user.dbObjectId()
}
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.