Skip to content

Commit

Permalink
Avoid duplicated injections
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed May 18, 2019
1 parent 6f148fa commit 3aff9e6
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import { StyleSheet, View, AppRegistry } from 'react-native';
import StaticContainer from 'static-container';
import PropTypes from 'prop-types';
import React, { Component } from "react";
import { StyleSheet, View, AppRegistry } from "react-native";
import StaticContainer from "static-container";
import PropTypes from "prop-types";

const styles = StyleSheet.create({
container: {
Expand All @@ -14,8 +14,8 @@ class Provider extends Component {
store: PropTypes.shape({
subscribe: PropTypes.func.isRequired,
dispatch: PropTypes.func.isRequired,
getState: PropTypes.func.isRequired,
}),
getState: PropTypes.func.isRequired
})
};

getChildContext() {
Expand All @@ -27,16 +27,19 @@ class Provider extends Component {
}
}

AppRegistry.setWrapperComponentProvider(function() {
return function RootSiblingsWrapper(props) {
return (
<View style={styles.container}>
{props.children}
<RootSiblings />
</View>
);
};
});
if (!global.__rootSiblingsInjected) {
AppRegistry.setWrapperComponentProvider(function() {
return function RootSiblingsWrapper(props) {
return (
<View style={styles.container}>
{props.children}
<RootSiblings />
</View>
);
};
});
global.__rootSiblingsInjected = true;
}

let uuid = 0;
const triggers = [];
Expand Down Expand Up @@ -79,7 +82,10 @@ class RootSiblings extends Component {
const element = siblings[key];
if (element) {
const sibling = (
<StaticContainer key={`root-sibling-${key}`} shouldUpdate={!!this._updatedSiblings[key]}>
<StaticContainer
key={`root-sibling-${key}`}
shouldUpdate={!!this._updatedSiblings[key]}
>
{element}
</StaticContainer>
);
Expand Down

0 comments on commit 3aff9e6

Please sign in to comment.