react-native-root-siblings
Advanced tools
Comparing version 4.0.5 to 4.0.6-0
@@ -7,3 +7,3 @@ import { ReactNode } from 'react'; | ||
} | ||
interface RootControllerAction { | ||
export interface RootControllerAction { | ||
change: RootControllerChanges; | ||
@@ -22,2 +22,1 @@ element: ReactNode; | ||
} | ||
export {}; |
@@ -21,2 +21,3 @@ import { Component, ReactChild, ReactNode } from 'react'; | ||
render(): JSX.Element; | ||
private commitChange; | ||
private invokeCallback; | ||
@@ -23,0 +24,0 @@ private renderSiblings; |
@@ -14,43 +14,4 @@ import React, { Component } from 'react'; | ||
componentDidMount() { | ||
this.props.controller.setCallback((id, { change, element, updateCallback }) => { | ||
const siblings = Array.from(this.siblingsPool); | ||
const index = siblings.findIndex(sibling => sibling.id === id); | ||
if (change === RootControllerChanges.Remove) { | ||
if (index > -1) { | ||
siblings.splice(index, 1); | ||
} | ||
else { | ||
this.invokeCallback(updateCallback); | ||
return; | ||
} | ||
} | ||
else if (change === RootControllerChanges.Update) { | ||
if (index > -1) { | ||
siblings.splice(index, 1, { | ||
element, | ||
id | ||
}); | ||
this.updatedSiblings.add(id); | ||
} | ||
else { | ||
this.invokeCallback(updateCallback); | ||
return; | ||
} | ||
} | ||
else { | ||
if (index > -1) { | ||
siblings.splice(index, 1); | ||
} | ||
siblings.push({ | ||
element, | ||
id | ||
}); | ||
this.updatedSiblings.add(id); | ||
} | ||
this.siblingsPool = siblings; | ||
setImmediate(() => { | ||
this.setState({ | ||
siblings | ||
}, () => this.invokeCallback(updateCallback)); | ||
}); | ||
this.props.controller.setCallback((id, change) => { | ||
setImmediate(() => this.commitChange(id, change)); | ||
}); | ||
@@ -67,2 +28,42 @@ } | ||
} | ||
commitChange(id, { change, element, updateCallback }) { | ||
const siblings = Array.from(this.siblingsPool); | ||
const index = siblings.findIndex(sibling => sibling.id === id); | ||
if (change === RootControllerChanges.Remove) { | ||
if (index > -1) { | ||
siblings.splice(index, 1); | ||
} | ||
else { | ||
this.invokeCallback(updateCallback); | ||
return; | ||
} | ||
} | ||
else if (change === RootControllerChanges.Update) { | ||
if (index > -1) { | ||
siblings.splice(index, 1, { | ||
element, | ||
id | ||
}); | ||
this.updatedSiblings.add(id); | ||
} | ||
else { | ||
this.invokeCallback(updateCallback); | ||
return; | ||
} | ||
} | ||
else { | ||
if (index > -1) { | ||
siblings.splice(index, 1); | ||
} | ||
siblings.push({ | ||
element, | ||
id | ||
}); | ||
this.updatedSiblings.add(id); | ||
} | ||
this.siblingsPool = siblings; | ||
this.setState({ | ||
siblings | ||
}, () => this.invokeCallback(updateCallback)); | ||
} | ||
invokeCallback(callback) { | ||
@@ -69,0 +70,0 @@ if (callback) { |
@@ -48,3 +48,3 @@ import React, { useEffect, useState } from 'react'; | ||
const [sibling] = useState(() => { | ||
const { Root: Parent, manager: parentManager } = wrapRootComponent(ChildrenWrapper, renderSibling); | ||
const { Root: parentRoot, manager: parentManager } = wrapRootComponent(ChildrenWrapper, renderSibling); | ||
managerStack.push(parentManager); | ||
@@ -55,3 +55,3 @@ if (inactive) { | ||
return { | ||
Root: Parent, | ||
Root: parentRoot, | ||
manager: parentManager | ||
@@ -58,0 +58,0 @@ }; |
{ | ||
"version": "4.0.5", | ||
"version": "4.0.6-0", | ||
"name": "react-native-root-siblings", | ||
@@ -4,0 +4,0 @@ "repository": { |
@@ -9,3 +9,3 @@ import { ReactNode } from 'react'; | ||
interface RootControllerAction { | ||
export interface RootControllerAction { | ||
change: RootControllerChanges; | ||
@@ -12,0 +12,0 @@ element: ReactNode; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
721
36905
3