Skip to content

Commit

Permalink
refactor: switch to hard tabs for indentation (cloudflare#76)
Browse files Browse the repository at this point in the history
* refactor: switch to hard tabs for indentation
* chore: update to latest prettier
  • Loading branch information
Cherry authored Jul 21, 2022
1 parent 2f38f32 commit c7bea35
Show file tree
Hide file tree
Showing 115 changed files with 17,627 additions and 17,627 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
root = true

[*]
indent_size = 2
indent_style = space
indent_style = tab
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
34 changes: 17 additions & 17 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"semi": true,
"printWidth": 100,
"singleQuote": true,
"bracketSpacing": true,
"insertPragma": false,
"requirePragma": false,
"jsxSingleQuote": false,
"bracketSameLine": false,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": true,
"quoteProps": "consistent",
"proseWrap": "preserve",
"trailingComma": "es5",
"arrowParens": "avoid",
"useTabs": false,
"tabWidth": 2
"semi": true,
"printWidth": 100,
"singleQuote": true,
"bracketSpacing": true,
"insertPragma": false,
"requirePragma": false,
"jsxSingleQuote": false,
"bracketSameLine": false,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": true,
"quoteProps": "consistent",
"proseWrap": "preserve",
"trailingComma": "es5",
"arrowParens": "avoid",
"useTabs": true,
"tabWidth": 2
}
88 changes: 44 additions & 44 deletions examples/ab-test.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
// Serve different variants of your site to different visitors

export default {
/**
* @param {Request} request
* @returns {Promise<Response>}
*/
async fetch(request) {
const name = 'experiment-0';
let group; // 'control' or 'test', set below
let isNew = false; // is the group newly-assigned?
/**
* @param {Request} request
* @returns {Promise<Response>}
*/
async fetch(request) {
const name = 'experiment-0';
let group; // 'control' or 'test', set below
let isNew = false; // is the group newly-assigned?

// Determine which group this request is in.
const cookie = request.headers.get('Cookie');
if (cookie && cookie.includes(`${name}=control`)) {
group = 'control';
} else if (cookie && cookie.includes(`${name}=test`)) {
group = 'test';
} else {
// 50/50 Split
group = Math.random() < 0.5 ? 'control' : 'test';
isNew = true;
}
// Determine which group this request is in.
const cookie = request.headers.get('Cookie');
if (cookie && cookie.includes(`${name}=control`)) {
group = 'control';
} else if (cookie && cookie.includes(`${name}=test`)) {
group = 'test';
} else {
// 50/50 Split
group = Math.random() < 0.5 ? 'control' : 'test';
isNew = true;
}

// We'll prefix the request path with the experiment name. This way,
// the origin server merely has to have two copies of the site under
// top-level directories named "control" and "test".
let url = new URL(request.url);
url.pathname = `/${group}${url.pathname}`;
// We'll prefix the request path with the experiment name. This way,
// the origin server merely has to have two copies of the site under
// top-level directories named "control" and "test".
let url = new URL(request.url);
url.pathname = `/${group}${url.pathname}`;

// dispatch the modified request
const response = await fetch(url, {
method: request.method,
headers: request.headers,
});
// dispatch the modified request
const response = await fetch(url, {
method: request.method,
headers: request.headers,
});

if (isNew) {
// The experiment was newly-assigned, so add
// a Set-Cookie header to the response.
const newHeaders = new Headers(response.headers);
newHeaders.append('Set-Cookie', `${name}=${group}`);
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: newHeaders,
});
} else {
// Return response unmodified.
return response;
}
},
if (isNew) {
// The experiment was newly-assigned, so add
// a Set-Cookie header to the response.
const newHeaders = new Headers(response.headers);
newHeaders.append('Set-Cookie', `${name}=${group}`);
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: newHeaders,
});
} else {
// Return response unmodified.
return response;
}
},
};
58 changes: 29 additions & 29 deletions examples/aggregate-multiple-requests.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
// Make multiple requests, aggregate the responses
// and send them back as a single response.
export default {
/**
* @returns {Promise<Response>}
*/
async fetch() {
const init = {
method: 'GET',
headers: {
'Authorization': 'XXXXXX',
'Content-Type': 'text/plain',
},
};
/**
* @returns {Promise<Response>}
*/
async fetch() {
const init = {
method: 'GET',
headers: {
'Authorization': 'XXXXXX',
'Content-Type': 'text/plain',
},
};

const [btcResp, ethResp, ltcResp] = await Promise.all([
fetch('https://api.coinbase.com/v2/prices/BTC-USD/spot', init),
fetch('https://api.coinbase.com/v2/prices/ETH-USD/spot', init),
fetch('https://api.coinbase.com/v2/prices/LTC-USD/spot', init),
]);
const [btcResp, ethResp, ltcResp] = await Promise.all([
fetch('https://api.coinbase.com/v2/prices/BTC-USD/spot', init),
fetch('https://api.coinbase.com/v2/prices/ETH-USD/spot', init),
fetch('https://api.coinbase.com/v2/prices/LTC-USD/spot', init),
]);

const [btc, eth, ltc] = await Promise.all([btcResp.json(), ethResp.json(), ltcResp.json()]);
const [btc, eth, ltc] = await Promise.all([btcResp.json(), ethResp.json(), ltcResp.json()]);

const combined = {
btc: btc['data'].amount,
ltc: ltc['data'].amount,
eth: eth['data'].amount,
};
const combined = {
btc: btc['data'].amount,
ltc: ltc['data'].amount,
eth: eth['data'].amount,
};

return new Response(JSON.stringify(combined), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
},
return new Response(JSON.stringify(combined), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
},
};
Loading

0 comments on commit c7bea35

Please sign in to comment.