react-native-root-siblings
Advanced tools
Comparing version 3.0.0 to 3.1.0
42
index.js
import React, { Component, cloneElement } from 'react'; | ||
import { StyleSheet, View, AppRegistry } from 'react-native'; | ||
import StaticContainer from 'static-container'; | ||
import { Provider } from 'react-redux'; | ||
@@ -33,9 +34,13 @@ const styles = StyleSheet.create({ | ||
_siblings = {}; | ||
_stores = {}; | ||
_update = (id, element, callback) => { | ||
_update = (id, element, callback, store) => { | ||
const siblings = { ...this._siblings }; | ||
const stores = { ...this._stores }; | ||
if (siblings[id] && !element) { | ||
delete siblings[id]; | ||
delete stores[id]; | ||
} else if (element) { | ||
siblings[id] = element; | ||
stores[id] = store; | ||
} | ||
@@ -45,2 +50,3 @@ | ||
this._siblings = siblings; | ||
this._stores = stores; | ||
this.forceUpdate(callback); | ||
@@ -51,13 +57,23 @@ }; | ||
const siblings = this._siblings; | ||
const stores = this._stores; | ||
const elements = []; | ||
Object.keys(siblings).forEach((key) => { | ||
const element = siblings[key]; | ||
element && elements.push( | ||
<StaticContainer | ||
key={`root-sibling-${key}`} | ||
shouldUpdate={!!this._updatedSiblings[key]} | ||
> | ||
{element} | ||
</StaticContainer> | ||
); | ||
if (element) { | ||
const sibling = ( | ||
<StaticContainer | ||
key={`root-sibling-${key}`} | ||
shouldUpdate={!!this._updatedSiblings[key]} | ||
> | ||
{element} | ||
</StaticContainer> | ||
); | ||
const store = stores[key]; | ||
elements.push(store ? ( | ||
<Provider store={store} key={`root-sibling-${key}-provider`}> | ||
{sibling} | ||
</Provider> | ||
) : sibling); | ||
} | ||
}); | ||
@@ -78,7 +94,7 @@ this._updatedSiblings = {}; | ||
export default class { | ||
constructor(element, callback) { | ||
constructor(element, callback, store) { | ||
const id = uuid++; | ||
function update(element, callback) { | ||
function update(element, callback, store) { | ||
triggers.forEach(function (trigger) { | ||
trigger(id, element, callback); | ||
trigger(id, element, callback, store); | ||
}); | ||
@@ -93,3 +109,3 @@ }; | ||
update(element, callback); | ||
update(element, callback, store); | ||
this.update = update; | ||
@@ -96,0 +112,0 @@ this.destroy = destroy; |
{ | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"name": "react-native-root-siblings", | ||
@@ -11,3 +11,4 @@ "repository": { | ||
"dependencies": { | ||
"static-container": "^1.0.0" | ||
"static-container": "^1.0.0", | ||
"react-redux": "*" | ||
}, | ||
@@ -14,0 +15,0 @@ "keywords": [ |
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
8897
95
2
1
+ Addedreact-redux@*
+ Added@types/use-sync-external-store@0.0.6(transitive)
+ Addedreact@19.0.0(transitive)
+ Addedreact-redux@9.2.0(transitive)
+ Addeduse-sync-external-store@1.4.0(transitive)