Skip to content

Layer: now supports React context passing through, which affects all Layered components.#659

Merged
dzearing merged 9 commits into
microsoft:masterfrom
dzearing:layer-context-fix
Dec 9, 2016
Merged

Layer: now supports React context passing through, which affects all Layered components.#659
dzearing merged 9 commits into
microsoft:masterfrom
dzearing:layer-context-fix

Conversation

@dzearing

@dzearing dzearing commented Dec 6, 2016

Copy link
Copy Markdown
Member

Pull request checklist

Description of changes

Layers were not passing through React context, which prevented a number of integration scenarios that depend on context (like using React router or redux dispatcher accessed from context.)

Focus areas to test

All layered components should continue to function and render as expected.

@joschect joschect left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, I added some nits and suggestions.

/**
* Callback for when the layer is mounted.
*/
onLayerDidMount?: () => void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tentative suggestion: If you're going this route you might want to add a few other life cycle options, like onLayerWillMount().

private _hasMounted: boolean;
/**
* Used for notifying applicable Layers that a host is available/unavailable and to re-evaluate Layers that
* case about the specific host.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit typo should be "care" not "case"

/**
* The id property provided on a LayerHost that this Layer should render within.
*/
hostId?: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not have this be host?: string | htmlelement

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to to hostselector and add support for .querySelector.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding this one because we need the layerhost id and layer's hostid to match.

let doc = getDocument(this._rootElement);

if (hostId) {
return doc.getElementById(hostId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the element returned is null? It's unlikely and we expect them to pass in a good value but it could cause problems.

Also I think you need the conditional to be if (hostId && doc) to check for ssr.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm explicitly handling this... did you see the example?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at the _getHost call. It can return null and it's handled.

@dzearing dzearing merged commit a86981a into microsoft:master Dec 9, 2016
@dzearing dzearing deleted the layer-context-fix branch December 9, 2016 01:45
gokunymbus pushed a commit to gokunymbus/office-ui-fabric-react that referenced this pull request Jan 24, 2017
…Layered components. (microsoft#659)

* Fixing layer to respect context.

* Simplifying layer, adjusting to support react context, removing unnecessary code, adding test coverage.

* Adding change file.

* Fixing lint

* Fixing test.

* Adjusting LayerHost to be simpler and Layer to support conditionally render if targeted LayerHost is added/removed asynchrnously.

* fixing lint.

* Fixing comments.
@JasonGore JasonGore mentioned this pull request Jun 27, 2019
2 tasks
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants