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 / 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 / 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 / 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_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 / 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 / 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 / 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.prod.js
Last active July 20, 2018 19:59
Setup React App - Organizing React Application Part 1
const webpack = require('webpack');
const merge = require('webpack-merge');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: 'production',
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
@nairihar
nairihar / index.js
Last active July 26, 2018 13:32
Setup React App - Organizing React Application Part 1
import React from 'react';
import { render } from 'react-dom';
const App = () => <h1>Hello World</h1>;
render(<App />, document.getElementById('root'));
@nairihar
nairihar / index.html
Created July 20, 2018 20:17
Setup React App - Organizing React Application Part 1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Setup React App - Organizing React Application Part 1</title>
</head>
<body>
<div id="root"></div>
</body>
</html>