Skip to content

Instantly share code, notes, and snippets.

View nairihar's full-sized avatar
😎
Always busy

Nairi Harutyunyan nairihar

😎
Always busy
View GitHub Profile
@nairihar
nairihar / webpack.dev.js
Last active July 20, 2018 19:58
Setup React App - Organizing React Application Part 1
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: 'development',
devServer: {
contentBase: './dist'
}
});
@nairihar
nairihar / webpack.common.js
Last active July 20, 2018 19:57
Setup React App - Organizing React Application Part 1
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
app: './src/index.js'
},
module: {
rules: [
@nairihar
nairihar / package.json
Created July 19, 2018 14:12
Setup React App - Organizing React Application Part 1
{
"name": "react-application",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
@nairihar
nairihar / weak_set_example.js
Created July 9, 2018 12:45
JavaScript series, part 3, WeakMap and WeakSet, medium
const weakSet = new WeakSet();
const obj = {};
weakSet.add(obj);
weakSet.has(obj);
// true
weakSet.delete(obj);
// true
@nairihar
nairihar / weak_map_example_2.js
Created July 9, 2018 12:09
JavaScript series, part 3, WeakMap and WeakSet, medium
const weakMap = new WeakMap();
let obj = {};
weakMap.set(obj, 11);
weakMap.get(obj);
// 11
console.log(weakMap);
@nairihar
nairihar / weak_map_example_1.js
Created July 9, 2018 12:05
JavaScript series, part 3, WeakMap and WeakSet, medium
const weakMap = new WeakMap();
const obj = {};
weakMap.set(obj, 11);
weakMap.set(1,1);
// Uncaught TypeError: Invalid value used as weak map key
weakMap.get(obj);
// 11
@nairihar
nairihar / hint.txt
Created July 9, 2018 11:46
JavaScript series, part 3, WeakMap and WeakSet, medium
In some cases you won't have an access to modify the object.
So, what kind of cases they are?
@nairihar
nairihar / custom_WeakMap_problem_example.js
Last active July 6, 2018 19:59
JavaScript series, part 3, WeakMap and WeakSet, medium
const weakMap = new WeakMap(); // be sure you using custom WeakMap not native
const obj = Object.freeze({ hello: true });
weakMap.set(obj, 12);
@nairihar
nairihar / map_any_key_data_array_using_map.js
Last active July 1, 2018 17:53
JavaScript series, part 2, Map, medium
const myMap = new Map();
const arr1 = [];
const arr2 = [];
myMap.set(arr1, 1);
myMap.set(arr2, 2);
console.log([...myMap]);
/*
@nairihar
nairihar / map_any_key_data_array_using_object.js
Last active July 1, 2018 15:17
JavaScript series, part 2, Map, medium
const obj = {};
const arr1 = [];
const arr2 = [];
obj[arr1] = 1;
obj[arr2] = 2;
console.log(obj);
// {"": 2}