Skip to content

Instantly share code, notes, and snippets.

// header script 的 webpack.config.js 里做 externals 的声明,
// 并绑定到 __tidb 这个全局变量上,方便使用方通过全局变量注入 dependencies
externals: {
'prop-types': '__tidb.PropTypes',
'react-dom': '__tidb.ReactDOM',
'styled-components': '__tidb.styledComponents',
antd: '__tidb.antd',
polished: '__tidb.polished',
ramda: '__tidb.R',
react: '__tidb.React',

For the event tracking, I did something similar at Accordo. So, I would like to share my thoughts about the tracking design at FE:

  1. Encapsulate an EventTracking class for the common fields and the API call. Pseudocode may like follow:
class EventTracking {
    fields = {};

    constructor() {
        // Init evn related configs and common fields
@hustKiwi
hustKiwi / machine.js
Last active February 13, 2020 01:59
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
chrome.onMessage.onClicked.addListener(message => {
if (message === 'some action') {
chrome.tabs.query(
{
active: true,
currentWindow: true,
},
tabs => {
const activeTab = tabs[0];
chrome.tabs.executeScript(activeTab.id, {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://randomuser.me/api/');
xhr.onload = () => {
console.log(JSON.parse(xhr.responseText))
}
xhr.send();
@hustKiwi
hustKiwi / loops.js
Last active September 21, 2019 09:59
for (let i = 0; i < 5; i++) {
console.log(i);
}
let i = 0;
do {
console.log(i);
} while (++i < 5);
i = 0;
const car = {
size: 3,
wheel: 4,
type: 'LPG'
};
if (car.size >= 10) {
console.log('This car is large.');
} else if (car.wheel !== 4) {
console.log('This car is broken.');
// Arithmetic operators and Assignment
let x = 1;
let y = 2;
x += y;
console.log(x);
x = y++;
console.log(x);
console.log(y);
const str = 'Lesson 1';
str.length; // 8
str.charAt(1); // 'e'
str.concat(' - HTML Basics') // "Lesson 1 - HTML Basics"
str.includes('1') // true
'' + 32
'3.14' + 0.0015
false.toString()
[1, 2, 3].toString()
JSON.stringify({
key: 123
})
parseInt('3', 10)
parseInt('3.14', 10)