-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Outlet reference protocol change for liquid-fire #14149
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,15 @@ class DynamicScope { | |
this.view, this.outletState, this.rootOutletState, this.isTopLevel, this.targetObject | ||
); | ||
} | ||
|
||
get(key) { | ||
return this[key]; | ||
} | ||
|
||
set(key, value) { | ||
this[key] = value; | ||
return value; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes the shape for dynamic scope, and also most of the other things on the dynamic scope are private (and more importantly – not a Until we have the registration story figured out, we should just throw here (for both |
||
} | ||
|
||
const renderers = []; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import { OutletSyntax } from './syntax/outlet'; | |
import { MountSyntax } from './syntax/mount'; | ||
import { DynamicComponentSyntax } from './syntax/dynamic-component'; | ||
import { InputSyntax } from './syntax/input'; | ||
import { WithDynamicVarsSyntax } from 'glimmer-runtime'; | ||
|
||
|
||
let syntaxKeys = []; | ||
let syntaxes = []; | ||
|
@@ -25,3 +27,8 @@ registerSyntax('outlet', OutletSyntax); | |
registerSyntax('mount', MountSyntax); | ||
registerSyntax('component', DynamicComponentSyntax); | ||
registerSyntax('input', InputSyntax); | ||
registerSyntax('-with-dynamic-vars', class { | ||
static create(environment, args, templates, symbolTable) { | ||
return new WithDynamicVarsSyntax({ args, templates }); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This could have been a POJO instead of a class) |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ class OutletComponentReference { | |
|
||
|
||
let outletName = outletNameRef.value(); | ||
let outletStateRef = parentOutletStateRef.get(outletName); | ||
let outletStateRef = parentOutletStateRef.get('outlets').get(outletName); | ||
let newState = this.lastState = outletStateRef.value(); | ||
|
||
this.outletStateTag.update(outletStateRef.tag); | ||
|
@@ -201,7 +201,7 @@ const TOP_LEVEL_MANAGER = new TopLevelOutletComponentManager(); | |
|
||
class OutletComponentManager extends AbstractOutletComponentManager { | ||
create(definition, args, dynamicScope) { | ||
let outletStateReference = dynamicScope.outletState = dynamicScope.outletState.get(definition.outletName); | ||
let outletStateReference = dynamicScope.outletState = dynamicScope.outletState.get('outlets').get(definition.outletName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change feels a bit dubious to me – the reason for this change is that you could swap in the outlet state reference for a regular If we need to support replacing this with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we don't have to use an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't really need a separate reference type for outlet states at all. I suspect we would be better off solving this with a better type at the value level, not the reference level. |
||
let outletState = outletStateReference.value(); | ||
dynamicScope.targetObject = outletState.render.controller; | ||
return new StateBucket(outletState); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,4 +278,50 @@ moduleFor('outlet view', class extends RenderingTest { | |
|
||
this.assertText('HIBAR'); | ||
} | ||
|
||
['@test outletState can pass through user code (liquid-fire initimate API) ']() { | ||
this.registerTemplate('outer', 'A{{#-with-dynamic-vars outletState=(identity (-get-dynamic-var "outletState"))}}B{{outlet}}D{{/-with-dynamic-vars}}E'); | ||
this.registerTemplate('inner', 'C'); | ||
|
||
// This looks like it doesn't do anything, but its presence | ||
// guarantees that the outletState gets converted from a reference | ||
// to a value and then back to a reference. That is what we're | ||
// testing here. | ||
this.registerHelper('identity', ([a]) => a); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make this do something instead of pass-through? This allows you to test updating behavior (see below) |
||
|
||
let outletState = { | ||
render: { | ||
owner: this.owner, | ||
into: undefined, | ||
outlet: 'main', | ||
name: 'outer', | ||
controller: {}, | ||
ViewClass: undefined, | ||
template: this.owner.lookup('template:outer') | ||
}, | ||
outlets: { | ||
main: { | ||
render: { | ||
owner: this.owner, | ||
into: undefined, | ||
outlet: 'main', | ||
name: 'inner', | ||
controller: {}, | ||
ViewClass: undefined, | ||
template: this.owner.lookup('template:inner') | ||
}, | ||
outlets: Object.create(null) | ||
} | ||
} | ||
}; | ||
|
||
this.runTask(() => this.component.setOutletState({ render: {}, outlets: { main: outletState } }) ); | ||
|
||
runAppend(this.component); | ||
|
||
this.assertText('ABCDE'); | ||
|
||
this.assertStableRerender(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, we want to make sure the updating paths work and so we follow the I-N-U-R pattern for new tests. Maybe you can get your helper to override the template based on a dynamic property, which would allow you to change it to a new template then replace it with the original. (Or if you could get it to do something similar to what LF is ultimately doing, then even better.) |
||
} | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ef4 I think we can simplify this by making internal helpers just a function with this interface: https://github.com/tildeio/glimmer/blob/master/packages/glimmer-runtime/lib/environment.ts#L239-L241
Then you wouldn't need the
isInternalHelper
orglimmerNativeHelper
flags – which are problematic because a userland helper can pretend to be one of those just by assigning that property on them.Instead: