react-native-root-siblings
Advanced tools
Comparing version 4.0.0-beta.1 to 4.0.0-beta.2
{ | ||
"version": "4.0.0-beta.1", | ||
"version": "4.0.0-beta.2", | ||
"name": "react-native-root-siblings", | ||
@@ -4,0 +4,0 @@ "repository": { |
@@ -13,5 +13,11 @@ ## react-native-root-siblings [![npm version](https://badge.fury.io/js/react-native-root-siblings.svg)](http://badge.fury.io/js/react-native-root-siblings) | ||
## 4.x | ||
From 4.0 the redux context injection has been removed from the main module specified by package.json. | ||
If you want to pass redux store into sibling content, you have to make some changes in your import code. | ||
From 4.0 the redux context injection is not enabled by default, should be enabled with a store provider. | ||
``` | ||
// this should be called at the very beginning of your application | ||
import { enableStoreProvider } from 'react-native-root-siblings'; | ||
import { Provider } from 'react-redux'; | ||
enableStoreProvider(Provider); | ||
``` | ||
Change: | ||
@@ -18,0 +24,0 @@ ``` |
declare class RootSiblings { | ||
constructor(el: JSX.Element, callback?: () => void); | ||
constructor(el: JSX.Element, callback?: () => void, store?: object); | ||
update(el: JSX.Element, callback?: () => void): void; | ||
update(el: JSX.Element, callback?: () => void, store?: object): void; | ||
@@ -6,0 +6,0 @@ destroy(callback?: () => void): void; |
@@ -11,3 +11,2 @@ import React, { Component } from 'react'; | ||
function RootSiblingsWrapper(props) { | ||
@@ -29,2 +28,3 @@ return ( | ||
let Provider = null; | ||
let uuid = 0; | ||
@@ -36,2 +36,3 @@ const triggers = []; | ||
_siblings = {}; | ||
_stores = {}; | ||
@@ -53,11 +54,15 @@ componentDidMount() { | ||
_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; | ||
} | ||
this._updatedSiblings[id] = true; | ||
this._siblings = siblings; | ||
this._stores = stores; | ||
this.forceUpdate(callback); | ||
@@ -68,2 +73,3 @@ }; | ||
const siblings = this._siblings; | ||
const stores = this._stores; | ||
const elements = []; | ||
@@ -74,3 +80,6 @@ Object.keys(siblings).forEach(key => { | ||
const sibling = ( | ||
<StaticContainer key={`root-sibling-${key}`} shouldUpdate={!!this._updatedSiblings[key]}> | ||
<StaticContainer | ||
key={`root-sibling-${key}`} | ||
shouldUpdate={!!this._updatedSiblings[key]} | ||
> | ||
{element} | ||
@@ -80,3 +89,12 @@ </StaticContainer> | ||
elements.push(sibling); | ||
const store = stores[key]; | ||
if (store && Provider) { | ||
elements.push( | ||
<Provider store={store} key={`root-sibling-${key}-provider`}> | ||
{sibling} | ||
</Provider> | ||
); | ||
} else { | ||
elements.push(sibling); | ||
} | ||
} | ||
@@ -89,12 +107,16 @@ }); | ||
export function enableStoreProvider(StoreProvider) { | ||
Provider = StoreProvider; | ||
} | ||
export default class RootSiblingManager { | ||
constructor(element, callback) { | ||
constructor(element, callback, store) { | ||
const id = uuid++; | ||
function update(element, callback) { | ||
function update(element, callback, store) { | ||
if (triggers.length) { | ||
triggers.forEach(function(trigger) { | ||
trigger(id, element, callback); | ||
trigger(id, element, callback, store); | ||
}); | ||
} else { | ||
pendingSiblings[id] = [element, callback]; | ||
pendingSiblings[id] = [element, callback, store]; | ||
} | ||
@@ -113,3 +135,3 @@ } | ||
update(element, callback); | ||
update(element, callback, store); | ||
this.update = update; | ||
@@ -119,1 +141,2 @@ this.destroy = destroy; | ||
} | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
181
0
10233
7
124