-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Injector): Injectors were not updating for prop updates.
Updated props being passed through to injectors were not resolving in updates occurring on their inject functions.
- Loading branch information
Showing
6 changed files
with
141 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,56 @@ | ||
import React from 'react'; | ||
import React, { Component, PropTypes } from 'react'; | ||
import { Injector } from '../../../src/index.js'; | ||
import InjectableHeader from './InjectableHeader'; | ||
|
||
const PageOne = () => ( | ||
const Content = ({ active }) => ( | ||
<div> | ||
I am page one. | ||
<p>I am page one.</p> | ||
<p>My State is {active ? `active` : `inactive`}</p> | ||
</div> | ||
); | ||
export default Injector({ | ||
Content.propTypes = { | ||
active: PropTypes.bool.isRequired | ||
}; | ||
|
||
const Inject = ({ active }) => ( | ||
<div> | ||
<p>Injection from Page One</p> | ||
<p>The active prop value is: {active ? `active` : `inactive`}</p> | ||
</div> | ||
); | ||
Inject.propTypes = { | ||
active: PropTypes.bool.isRequired | ||
}; | ||
|
||
const InjectingContent = Injector({ | ||
to: InjectableHeader, | ||
inject: () => <div>Injection from Page One</div> | ||
})(PageOne); | ||
inject: Inject | ||
})(Content); | ||
|
||
/** | ||
* We wrap our injecting content with a class based component so we can track | ||
* state and pass down props, thereby adding behaviour. | ||
*/ | ||
class PageOne extends Component { | ||
state = { | ||
active: false | ||
} | ||
|
||
onClick = () => { | ||
this.setState({ active: !this.state.active }); | ||
} | ||
|
||
render() { | ||
const { active } = this.state; | ||
|
||
return ( | ||
<div> | ||
<InjectingContent active={active} /> | ||
|
||
<button onClick={this.onClick}>Change my state</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default PageOne; |
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