javascript 创作客户端api
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 创作客户端api相关的知识,希望对你有一定的参考价值。
/*https://www.shopify.com/partners/blog/28500611-using-javascript-to-super-power-your-clients-shopify-site*/
(function(window, $){
if(!$){
throw new Error('$ is not defined')
}
// private fields
let requestLimit = 50;
let collections = [];
let collectionsHandleMap = [];
let products = [];
let productsHandleMap = [];
// public static fields
// snow joe api
let api = {
}
api.init = function(){}
api.getProductsFor = function getProducts(collectionHandle,productHandle){
return $.get(`/collections/${collectionHandle}?view=pagination-endpoint`, function(response){
response = JSON.parse(response);
for (let i = 0; i < response.pages; i++) {
let pageNumber = 1 + i;
let $productRequest = $.get(`/collections/${collectionHandle}?view=products-endpoint&page=${pageNumber}`, function(response){
response = JSON.parse(response);
products.push(...response.products);
return response
});
}
})
}
api.getProducts = function(){
return products;
}
window.sj = api;
})(window, jQuery)
以上是关于javascript 创作客户端api的主要内容,如果未能解决你的问题,请参考以下文章
SignalR JavaScript客户端API调用连接
JavaScript学习指南。
JavaScript小技能:客户端 API
Leanplum api密钥暴露在客户端javascript上?
javascript 抽象工厂创作设计模式
javascript 简单的工厂创作设计模式