Refactor sandboxGlobals -> buildSandboxGlobals#245
Merged
rwjblue merged 1 commit intoember-fastboot:masterfrom Nov 1, 2019
Merged
Refactor sandboxGlobals -> buildSandboxGlobals#245rwjblue merged 1 commit intoember-fastboot:masterfrom
rwjblue merged 1 commit intoember-fastboot:masterfrom
Conversation
Contributor
|
We could default it to a function that does a cheap copy of the old property to ease migration. Making it a function just helps clue people into that they should be careful here, it doesn't mitigate data leaking between visits and the existing code already assigns. This doesn't prevent interior mutations and we already Object.assign the old sandboxGlobals property. |
kratiahuja
approved these changes
Oct 31, 2019
Contributor
kratiahuja
left a comment
There was a problem hiding this comment.
Once Kris's concerns are addressed.
This changes the system from providing default set of shared (and
therefore mutable) global properties to using a builder function to
generate the set of globals to be used _per visit_.
The `buildSandboxGlobals` function will receive the default set of
globals that FastBoot creates (currently this is `najax` and
`FastBoot`), and whatever the `buildSandboxGlobals` function returns is
what will ultimately be used. If `buildSandboxGlobals` is not provided,
a default implementation is used (it is essentially `defaultGlobals =>
defaultGlobals;`).
For example, to specify a custom global property named `AwesomeThing` to
be accessed within the sandboxed context:
```js
let fastboot = new FastBoot({
distPath: 'some/path/here',
buildSandboxGlobals(globals) {
return Object.assign({}, globals, {
AwesomeThing: 'Taco Cat'
});
}
});
```
If `sandboxGlobals` is passed (and `buildSandboxGlobals` is not) issue a
deprecation and automatically create a `buildSandboxGlobals` of the
following:
```js
globals => Object.assign({}, globals, options.sandboxGlobals);
```
e232e20 to
297ff53
Compare
Member
Author
|
Updated to default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This changes the system from providing default set of shared (and therefore mutable) global properties to using a builder function to generate the set of globals to be used per visit.
The
buildSandboxGlobalsfunction will receive the default set of globals that FastBoot creates (currently this isnajaxandFastBoot), and whatever thebuildSandboxGlobalsfunction returns is what will ultimately be used. IfbuildSandboxGlobalsis not provided, a default implementation is used (it is essentiallydefaultGlobals => defaultGlobals;).Closes #239