This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client scoped query recyclers (#513)
- Loading branch information
Roman Coedo
committed
Aug 8, 2017
1 parent
80e6f7f
commit 8fea657
Showing
5 changed files
with
65 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Component, Children } from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
import { ObservableQueryRecycler } from './queryRecycler'; | ||
|
||
class QueryRecyclerProvider extends Component { | ||
static propTypes = { | ||
children: PropTypes.element.isRequired | ||
}; | ||
|
||
static childContextTypes = { | ||
getQueryRecycler: PropTypes.func.isRequired | ||
}; | ||
|
||
private recyclers: WeakMap<Component, ObservableQueryRecycler>; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.recyclers = new WeakMap(); | ||
this.getQueryRecycler = this.getQueryRecycler.bind(this); | ||
} | ||
|
||
componentWillReceiveProps(nextProps, nextContext) { | ||
if (this.context.client !== nextContext.client) { | ||
this.recyclers = new WeakMap(); | ||
} | ||
} | ||
|
||
getQueryRecycler(component) { | ||
if (!this.recyclers.has(component)) { | ||
this.recyclers.set(component, new ObservableQueryRecycler()); | ||
} | ||
return this.recyclers.get(component); | ||
} | ||
|
||
getChildContext() { | ||
return ({ | ||
getQueryRecycler: this.getQueryRecycler | ||
}); | ||
} | ||
|
||
render() { | ||
return Children.only(this.props.children); | ||
} | ||
} | ||
|
||
export default QueryRecyclerProvider; |
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