Skip to content

Instantly share code, notes, and snippets.

@arthur-abogadil
Last active July 6, 2020 12:24
Show Gist options
  • Save arthur-abogadil/2511a0e2215460eb418db62fa7c83402 to your computer and use it in GitHub Desktop.
Save arthur-abogadil/2511a0e2215460eb418db62fa7c83402 to your computer and use it in GitHub Desktop.
for CC.
// Im not able to show some of the most important things ive written for my last customizer project
// as im bound by an NDA, but here i present some simple things that ive devised and used that helped // the architecture of the projects ive created much cleaner
// This is a very simple js idiom i developed early in the development
// of the customizer, it basically just uses the jquery rest call function
ub.loader = function (url, object_name, cb) {
$.ajax({
url: url,
type: "GET",
dataType: "json",
crossDomain: true,
contentType: "application/json",
headers: {"accessToken": (ub.user !== false) ? atob(ub.user.headerValue) : null},
success: function (response) {
cb(response[object_name], object_name);
}
});
};
// The interesting thing here is the cb parameter, which is the callback function parameter
// it helped in two things for all the API calls i need to do for the project,
//
// 1. it's a cleaner way to make the call, specify the endpoint, and the structural destination of
// the data object
// 2. specify a generic or specific preprocessor function that can check the consistency of the data // and transform it to a cleaner structure at the early stage while the backend requirements is
// yet final and is very mallable due to frequent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment