├── .gitignore ├── commonjs ├── lib.js ├── main1.js └── main2.js ├── commonjs_transpiled ├── lib.js ├── main1.js └── main2.js ├── es6 ├── lib.js ├── main1.js └── main2.js ├── es6_for_babel ├── lib.js ├── main1.js └── main2.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | -------------------------------------------------------------------------------- /commonjs/lib.js: -------------------------------------------------------------------------------- 1 | //------ lib.js ------ 2 | var mutableValue = 3; 3 | function incMutableValue() { 4 | mutableValue++; 5 | } 6 | module.exports = { 7 | mutableValue: mutableValue, 8 | incMutableValue: incMutableValue, 9 | }; 10 | -------------------------------------------------------------------------------- /commonjs/main1.js: -------------------------------------------------------------------------------- 1 | //------ main1.js ------ 2 | var mutableValue = require('./lib').mutableValue; 3 | var incMutableValue = require('./lib').incMutableValue; 4 | 5 | // The imported value is a (disconnected) snapshot 6 | console.log(mutableValue); // 3 7 | incMutableValue(); 8 | console.log(mutableValue); // 3 9 | 10 | // The imported value can be changed 11 | mutableValue++; 12 | console.log(mutableValue); // 4 13 | -------------------------------------------------------------------------------- /commonjs/main2.js: -------------------------------------------------------------------------------- 1 | //------ main2.js ------ 2 | var lib = require('./lib'); 3 | 4 | // The imported value is a (disconnected) snapshot 5 | console.log(lib.mutableValue); // 3 6 | lib.incMutableValue(); 7 | console.log(lib.mutableValue); // 3 8 | 9 | // The imported value can be changed 10 | lib.mutableValue++; 11 | console.log(lib.mutableValue); // 4 12 | -------------------------------------------------------------------------------- /commonjs_transpiled/lib.js: -------------------------------------------------------------------------------- 1 | //------ lib.js ------ 2 | "use strict"; 3 | 4 | Object.defineProperty(exports, "__esModule", { 5 | value: true 6 | }); 7 | exports.incMutableValue = incMutableValue; 8 | var mutableValue = 3; 9 | exports.mutableValue = mutableValue; 10 | 11 | function incMutableValue() { 12 | exports.mutableValue = mutableValue += 1; 13 | } -------------------------------------------------------------------------------- /commonjs_transpiled/main1.js: -------------------------------------------------------------------------------- 1 | //------ main1.js ------ 2 | 'use strict'; 3 | 4 | var _lib = require('./lib'); 5 | 6 | // The imported value is live 7 | console.log(_lib.mutableValue); // 3 8 | (0, _lib.incMutableValue)(); 9 | console.log(_lib.mutableValue); // 4 -------------------------------------------------------------------------------- /commonjs_transpiled/main2.js: -------------------------------------------------------------------------------- 1 | //------ main2.js ------ 2 | 'use strict'; 3 | 4 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } 5 | 6 | var _lib = require('./lib'); 7 | 8 | var lib = _interopRequireWildcard(_lib); 9 | 10 | // The imported value is live 11 | console.log(lib.mutableValue); // 3 12 | lib.incMutableValue(); 13 | console.log(lib.mutableValue); // 4 -------------------------------------------------------------------------------- /es6/lib.js: -------------------------------------------------------------------------------- 1 | //------ lib.js ------ 2 | export let mutableValue = 3; 3 | export function incMutableValue() { 4 | mutableValue++; 5 | } 6 | -------------------------------------------------------------------------------- /es6/main1.js: -------------------------------------------------------------------------------- 1 | //------ main1.js ------ 2 | import { mutableValue, incMutableValue } from './lib'; 3 | 4 | // The imported value is live 5 | console.log(mutableValue); // 3 6 | incMutableValue(); 7 | console.log(mutableValue); // 4 8 | 9 | // The imported value can’t be changed 10 | mutableValue++; // TypeError 11 | -------------------------------------------------------------------------------- /es6/main2.js: -------------------------------------------------------------------------------- 1 | //------ main2.js ------ 2 | import * as lib from './lib'; 3 | 4 | // The imported value is live 5 | console.log(lib.mutableValue); // 3 6 | lib.incMutableValue(); 7 | console.log(lib.mutableValue); // 4 8 | 9 | // The imported value can’t be changed 10 | lib.mutableValue++; // TypeError 11 | -------------------------------------------------------------------------------- /es6_for_babel/lib.js: -------------------------------------------------------------------------------- 1 | //------ lib.js ------ 2 | export let mutableValue = 3; 3 | export function incMutableValue() { 4 | mutableValue++; 5 | } 6 | -------------------------------------------------------------------------------- /es6_for_babel/main1.js: -------------------------------------------------------------------------------- 1 | //------ main1.js ------ 2 | import { mutableValue, incMutableValue } from './lib'; 3 | 4 | // The imported value is live 5 | console.log(mutableValue); // 3 6 | incMutableValue(); 7 | console.log(mutableValue); // 4 8 | -------------------------------------------------------------------------------- /es6_for_babel/main2.js: -------------------------------------------------------------------------------- 1 | //------ main2.js ------ 2 | import * as lib from './lib'; 3 | 4 | // The imported value is live 5 | console.log(lib.mutableValue); // 3 6 | lib.incMutableValue(); 7 | console.log(lib.mutableValue); // 4 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts" : { 3 | "transpile" : "babel --modules common --out-dir commonjs_transpiled es6_for_babel" 4 | } 5 | } 6 | --------------------------------------------------------------------------------