Skip to content

Imported modules should be cached / a singleton, closes #427#428

Merged
odino merged 1 commit into2.5.xfrom
imported-moduled-cache
May 12, 2021
Merged

Imported modules should be cached / a singleton, closes #427#428
odino merged 1 commit into2.5.xfrom
imported-moduled-cache

Conversation

@odino
Copy link
Copy Markdown
Collaborator

@odino odino commented May 12, 2021

With this change, a module that's been imported is now cached.
This means that every time you call require('module') you will
receive back the same evaluated result, meaning changes you make
on that result will be persisted. This only applies to require
and not source, as source is intended to be used in order to
always evaluate a block of fresh code in the current environment.

Before:

$ require('@runtime').name = "xxx"
$ require('@runtime').name
abs

After:

$ require('@runtime').name = "xxx"
$ require('@runtime').name
xxx

With this change, a module that's been imported is now cached.
This means that every time you call `require('module')` you will
receive back the same evaluated result, meaning changes you make
on that result will be persisted. This only applies to `require`
and not `source`, as `source` is intended to be used in order to
always evaluate a block of fresh code in the current environment.

Before:

```
$ require('@runtime').name = "xxx"
$ require('@runtime').name
abs
```

After:

```
$ require('@runtime').name = "xxx"
$ require('@runtime').name
xxx
```
@odino odino added this to the 2.5.x milestone May 12, 2021
@odino odino merged commit 1e18b23 into 2.5.x May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant