-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the
env
more generally consistent (JIT)
Previously, the `env` was a bag of properties, and got frequently extended or modified (in largely predictable ways). The consequence is that even though the environment is conceptually a single concept, it got treated internally as a megamorphic shapeless entity. For what it’s worth, this JIT confusion was somewhat mirrored by a confusion when reading the code: it was never precisely clear what the `env` would look like from the perspective of a human reader. This commit changes the environment to be a single class. There are only two kinds of child environments (a change in the `view` and a change to `outletState`), and there are now methods on `env` to make that simple and predictable. The consequence is that all methods that take an `env` now go down a fast path when accessing it, and human readers of the code can feel confident about what the environment looks like.
- Loading branch information
Showing
8 changed files
with
78 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import defaultEnv from "ember-htmlbars/env"; | ||
|
||
export default function RenderEnv(options) { | ||
this.lifecycleHooks = options.lifecycleHooks || []; | ||
this.renderedViews = options.renderedViews || []; | ||
this.renderedNodes = options.renderedNodes || {}; | ||
this.hasParentOutlet = options.hasParentOutlet || false; | ||
|
||
this.view = options.view; | ||
this.outletState = options.outletState; | ||
this.container = options.container; | ||
this.renderer = options.renderer; | ||
this.dom = options.dom; | ||
|
||
this.hooks = defaultEnv.hooks; | ||
this.helpers = defaultEnv.helpers; | ||
this.useFragmentCache = defaultEnv.useFragmentCache; | ||
} | ||
|
||
RenderEnv.build = function(view) { | ||
return new RenderEnv({ | ||
view: view, | ||
outletState: view.outletState, | ||
container: view.container, | ||
renderer: view.renderer, | ||
dom: view.renderer._dom | ||
}); | ||
}; | ||
|
||
RenderEnv.prototype.childWithView = function(view) { | ||
return new RenderEnv({ | ||
view: view, | ||
outletState: this.outletState, | ||
container: this.container, | ||
renderer: this.renderer, | ||
dom: this.dom, | ||
lifecycleHooks: this.lifecycleHooks, | ||
renderedViews: this.renderedViews, | ||
renderedNodes: this.renderedNodes, | ||
hasParentOutlet: this.hasParentOutlet | ||
}); | ||
}; | ||
|
||
RenderEnv.prototype.childWithOutletState = function(outletState, hasParentOutlet=this.hasParentOutlet) { | ||
return new RenderEnv({ | ||
view: this.view, | ||
outletState: outletState, | ||
container: this.container, | ||
renderer: this.renderer, | ||
dom: this.dom, | ||
lifecycleHooks: this.lifecycleHooks, | ||
renderedViews: this.renderedViews, | ||
renderedNodes: this.renderedNodes, | ||
hasParentOutlet: hasParentOutlet | ||
}); | ||
}; |
This file contains 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
This file contains 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
This file contains 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