From f4d400d02167747d4de3967589294fad1948fe31 Mon Sep 17 00:00:00 2001 From: Mike MacCana Date: Fri, 28 Sep 2018 12:03:57 +0100 Subject: [PATCH 1/6] Replace vague 'may not' with definitive 'will not' This vagueness of 'may' has caused a great deal of confusion. See https://stackoverflow.com/questions/8887318/understanding-node-js-modules-multiple-requires-return-the-same-object --- doc/api/modules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 9919a675169e8b..9ced8ac810aaf5 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -200,7 +200,7 @@ Modules are cached after the first time they are loaded. This means (among other things) that every call to `require('foo')` will get exactly the same object returned, if it would resolve to the same file. -Multiple calls to `require('foo')` may not cause the module code to be +Multiple calls to `require('foo')` will not cause the module code to be executed multiple times. This is an important feature. With it, "partially done" objects can be returned, thus allowing transitive dependencies to be loaded even when they would cause cycles. From cb473e7cf6be1219257d115e7f2027b57d100578 Mon Sep 17 00:00:00 2001 From: Mike MacCana Date: Fri, 28 Sep 2018 23:32:46 +0100 Subject: [PATCH 2/6] Mention modules will load once by default. --- doc/api/modules.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 9ced8ac810aaf5..cfcb460465665d 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -200,10 +200,12 @@ Modules are cached after the first time they are loaded. This means (among other things) that every call to `require('foo')` will get exactly the same object returned, if it would resolve to the same file. -Multiple calls to `require('foo')` will not cause the module code to be -executed multiple times. This is an important feature. With it, -"partially done" objects can be returned, thus allowing transitive -dependencies to be loaded even when they would cause cycles. +By default (provided the `require.cache` is not modified) ,ultiple calls to +`require('foo')` will not cause the module code to be executed multiple times. + +This is an important feature. With it, "partially done" objects can be returned, +thus allowing transitive dependencies to be loaded even when they would cause +cycles. To have a module execute code multiple times, export a function, and call that function. From 43e4208c936272729acdf36aedf82d4ba05c9ea7 Mon Sep 17 00:00:00 2001 From: Mike MacCana Date: Fri, 28 Sep 2018 23:34:54 +0100 Subject: [PATCH 3/6] Damn typo --- doc/api/modules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index cfcb460465665d..97462cbf362bc5 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -200,7 +200,7 @@ Modules are cached after the first time they are loaded. This means (among other things) that every call to `require('foo')` will get exactly the same object returned, if it would resolve to the same file. -By default (provided the `require.cache` is not modified) ,ultiple calls to +By default (provided the `require.cache` is not modified), multiple calls to `require('foo')` will not cause the module code to be executed multiple times. This is an important feature. With it, "partially done" objects can be returned, From 93b7750b31df3b9c2ce2ec8abb13b153e15d53ab Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 30 Sep 2018 09:37:25 -0700 Subject: [PATCH 4/6] Update modules.md --- doc/api/modules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 97462cbf362bc5..c0098e74e1e86e 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -200,7 +200,7 @@ Modules are cached after the first time they are loaded. This means (among other things) that every call to `require('foo')` will get exactly the same object returned, if it would resolve to the same file. -By default (provided the `require.cache` is not modified), multiple calls to +Provided `require.cache` is not modified, multiple calls to `require('foo')` will not cause the module code to be executed multiple times. This is an important feature. With it, "partially done" objects can be returned, From 58e2fee0d143faf969ddeb13eb369dd78239ebbb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 30 Sep 2018 09:37:54 -0700 Subject: [PATCH 5/6] Update modules.md --- doc/api/modules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index c0098e74e1e86e..29c8d9eb1c8243 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -203,7 +203,7 @@ exactly the same object returned, if it would resolve to the same file. Provided `require.cache` is not modified, multiple calls to `require('foo')` will not cause the module code to be executed multiple times. -This is an important feature. With it, "partially done" objects can be returned, +This is an important feature. With it, "partially done" objects can be returned, thus allowing transitive dependencies to be loaded even when they would cause cycles. From f4bdf886aba81840eab77b70c7e982fc820d4103 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 30 Sep 2018 09:40:06 -0700 Subject: [PATCH 6/6] Update modules.md --- doc/api/modules.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 29c8d9eb1c8243..bdf2ab34ff8fa3 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -202,7 +202,6 @@ exactly the same object returned, if it would resolve to the same file. Provided `require.cache` is not modified, multiple calls to `require('foo')` will not cause the module code to be executed multiple times. - This is an important feature. With it, "partially done" objects can be returned, thus allowing transitive dependencies to be loaded even when they would cause cycles.