react-native-root-siblings
Advanced tools
Comparing version 4.0.0-beta.7 to 4.0.0-beta.8
@@ -1,11 +0,5 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
function ChildrenWrapper(props) { | ||
import React from 'react'; | ||
export default function ChildrenWrapper(props) { | ||
return <>{props.children}</>; | ||
} | ||
exports.default = ChildrenWrapper; | ||
//# sourceMappingURL=ChildrenWrapper.js.map |
@@ -1,4 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var RootControllerChanges; | ||
export var RootControllerChanges; | ||
(function (RootControllerChanges) { | ||
@@ -8,5 +6,5 @@ RootControllerChanges[RootControllerChanges["Insert"] = 0] = "Insert"; | ||
RootControllerChanges[RootControllerChanges["Remove"] = 2] = "Remove"; | ||
})(RootControllerChanges = exports.RootControllerChanges || (exports.RootControllerChanges = {})); | ||
var RootController = /** @class */ (function () { | ||
function RootController() { | ||
})(RootControllerChanges || (RootControllerChanges = {})); | ||
export default class RootController { | ||
constructor() { | ||
this.siblings = new Set(); | ||
@@ -16,7 +14,7 @@ this.pendingActions = []; | ||
} | ||
RootController.prototype.update = function (id, element, callback) { | ||
update(id, element, callback) { | ||
if (!this.siblings.has(id)) { | ||
this.emit(id, { | ||
change: RootControllerChanges.Insert, | ||
element: element, | ||
element, | ||
updateCallback: callback | ||
@@ -29,8 +27,8 @@ }); | ||
change: RootControllerChanges.Update, | ||
element: element, | ||
element, | ||
updateCallback: callback | ||
}); | ||
} | ||
}; | ||
RootController.prototype.destroy = function (id, callback) { | ||
} | ||
destroy(id, callback) { | ||
if (this.siblings.has(id)) { | ||
@@ -47,11 +45,10 @@ this.emit(id, { | ||
} | ||
}; | ||
RootController.prototype.setCallback = function (callback) { | ||
} | ||
setCallback(callback) { | ||
this.callback = callback; | ||
this.pendingActions.forEach(function (_a) { | ||
var id = _a.id, action = _a.action; | ||
this.pendingActions.forEach(({ id, action }) => { | ||
callback(id, action); | ||
}); | ||
}; | ||
RootController.prototype.emit = function (id, action) { | ||
} | ||
emit(id, action) { | ||
if (this.callback) { | ||
@@ -62,10 +59,8 @@ this.callback(id, action); | ||
this.pendingActions.push({ | ||
action: action, | ||
id: id | ||
action, | ||
id | ||
}); | ||
} | ||
}; | ||
return RootController; | ||
}()); | ||
exports.default = RootController; | ||
} | ||
} | ||
//# sourceMappingURL=RootController.js.map |
@@ -1,47 +0,18 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importStar(require("react")); | ||
var static_container_1 = __importDefault(require("static-container")); | ||
var RootController_1 = require("./RootController"); | ||
var default_1 = /** @class */ (function (_super) { | ||
__extends(default_1, _super); | ||
function default_1(props) { | ||
var _this = _super.call(this, props) || this; | ||
_this.updatedSiblings = new Set(); | ||
_this.siblingsPool = []; | ||
_this.state = { | ||
import React, { Component } from 'react'; | ||
import StaticContainer from 'static-container'; | ||
import { RootControllerChanges } from './RootController'; | ||
export default class extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.updatedSiblings = new Set(); | ||
this.siblingsPool = []; | ||
this.state = { | ||
siblings: [] | ||
}; | ||
return _this; | ||
} | ||
default_1.prototype.componentDidMount = function () { | ||
var _this = this; | ||
this.props.controller.setCallback(function (id, _a) { | ||
var change = _a.change, element = _a.element, updateCallback = _a.updateCallback; | ||
var siblings = Array.from(_this.siblingsPool); | ||
var index = siblings.findIndex(function (sibling) { return sibling.id === id; }); | ||
if (change === RootController_1.RootControllerChanges.Remove) { | ||
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) { | ||
@@ -51,16 +22,16 @@ siblings.splice(index, 1); | ||
else { | ||
_this.invokeCallback(updateCallback); | ||
this.invokeCallback(updateCallback); | ||
return; | ||
} | ||
} | ||
else if (change === RootController_1.RootControllerChanges.Update) { | ||
else if (change === RootControllerChanges.Update) { | ||
if (index > -1) { | ||
siblings.splice(index, 1, { | ||
element: element, | ||
id: id | ||
element, | ||
id | ||
}); | ||
_this.updatedSiblings.add(id); | ||
this.updatedSiblings.add(id); | ||
} | ||
else { | ||
_this.invokeCallback(updateCallback); | ||
this.invokeCallback(updateCallback); | ||
return; | ||
@@ -74,17 +45,17 @@ } | ||
siblings.push({ | ||
element: element, | ||
id: id | ||
element, | ||
id | ||
}); | ||
_this.updatedSiblings.add(id); | ||
this.updatedSiblings.add(id); | ||
} | ||
_this.siblingsPool = siblings; | ||
_this.setState({ | ||
siblings: siblings | ||
}, function () { return _this.invokeCallback(updateCallback); }); | ||
this.siblingsPool = siblings; | ||
this.setState({ | ||
siblings | ||
}, () => this.invokeCallback(updateCallback)); | ||
}); | ||
}; | ||
default_1.prototype.componentDidUpdate = function () { | ||
} | ||
componentDidUpdate() { | ||
this.updatedSiblings.clear(); | ||
}; | ||
default_1.prototype.render = function () { | ||
} | ||
render() { | ||
return (<> | ||
@@ -94,19 +65,17 @@ {this.props.children} | ||
</>); | ||
}; | ||
default_1.prototype.invokeCallback = function (callback) { | ||
} | ||
invokeCallback(callback) { | ||
if (callback) { | ||
callback(); | ||
} | ||
}; | ||
default_1.prototype.renderSiblings = function () { | ||
var _this = this; | ||
return this.state.siblings.map(function (_a) { | ||
var id = _a.id, element = _a.element; | ||
return (<static_container_1.default key={"root-sibling-" + id} shouldUpdate={_this.updatedSiblings.has(id)}> | ||
{_this.wrapSibling(element)} | ||
</static_container_1.default>); | ||
} | ||
renderSiblings() { | ||
return this.state.siblings.map(({ id, element }) => { | ||
return (<StaticContainer key={`root-sibling-${id}`} shouldUpdate={this.updatedSiblings.has(id)}> | ||
{this.wrapSibling(element)} | ||
</StaticContainer>); | ||
}); | ||
}; | ||
default_1.prototype.wrapSibling = function (element) { | ||
var renderSibling = this.props.renderSibling; | ||
} | ||
wrapSibling(element) { | ||
const { renderSibling } = this.props; | ||
if (renderSibling) { | ||
@@ -118,6 +87,4 @@ return renderSibling(element); | ||
} | ||
}; | ||
return default_1; | ||
}(react_1.Component)); | ||
exports.default = default_1; | ||
} | ||
} | ||
//# sourceMappingURL=RootSiblings.js.map |
@@ -1,11 +0,6 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = require("react"); | ||
var react_native_1 = require("react-native"); | ||
var ChildrenWrapper_1 = __importDefault(require("./ChildrenWrapper")); | ||
var wrapRootComponent_1 = __importDefault(require("./wrapRootComponent")); | ||
var siblingWrapper = function (sibling) { return sibling; }; | ||
import { useEffect, useState } from 'react'; | ||
import { AppRegistry } from 'react-native'; | ||
import ChildrenWrapper from './ChildrenWrapper'; | ||
import wrapRootComponent from './wrapRootComponent'; | ||
let siblingWrapper = sibling => sibling; | ||
function renderSibling(sibling) { | ||
@@ -15,3 +10,3 @@ return siblingWrapper(sibling); | ||
if (!global.__rootSiblingsInjected && !global.__rootSiblingsDisabled) { | ||
react_native_1.AppRegistry.setWrapperComponentProvider(function () { | ||
AppRegistry.setWrapperComponentProvider(() => { | ||
return Root; | ||
@@ -21,25 +16,22 @@ }); | ||
} | ||
function setSiblingWrapper(wrapper) { | ||
export function setSiblingWrapper(wrapper) { | ||
siblingWrapper = wrapper; | ||
} | ||
exports.setSiblingWrapper = setSiblingWrapper; | ||
var _a = wrapRootComponent_1.default(ChildrenWrapper_1.default, renderSibling), Root = _a.Root, manager = _a.manager; | ||
var uuid = 0; | ||
var RootSiblingsManager = /** @class */ (function () { | ||
function RootSiblingsManager(element, callback) { | ||
this.id = "root-sibling-" + (uuid + 1); | ||
const { Root, manager } = wrapRootComponent(ChildrenWrapper, renderSibling); | ||
let uuid = 0; | ||
export default class RootSiblingsManager { | ||
constructor(element, callback) { | ||
this.id = `root-sibling-${uuid + 1}`; | ||
manager.update(this.id, element, callback); | ||
uuid++; | ||
} | ||
RootSiblingsManager.prototype.update = function (element, callback) { | ||
update(element, callback) { | ||
manager.update(this.id, element, callback); | ||
}; | ||
RootSiblingsManager.prototype.destroy = function (callback) { | ||
} | ||
destroy(callback) { | ||
manager.destroy(this.id, callback); | ||
}; | ||
return RootSiblingsManager; | ||
}()); | ||
exports.default = RootSiblingsManager; | ||
function RootSiblingProtal(props) { | ||
var _a = react_1.useState(null), sibling = _a[0], setSibling = _a[1]; | ||
} | ||
} | ||
export function RootSiblingProtal(props) { | ||
const [sibling, setSibling] = useState(null); | ||
if (!sibling) { | ||
@@ -51,5 +43,5 @@ setSibling(new RootSiblingsManager(props.children)); | ||
} | ||
react_1.useEffect(function () { | ||
useEffect(() => { | ||
if (sibling) { | ||
return function () { return sibling.destroy(); }; | ||
return () => sibling.destroy(); | ||
} | ||
@@ -59,3 +51,2 @@ }, [sibling]); | ||
} | ||
exports.RootSiblingProtal = RootSiblingProtal; | ||
//# sourceMappingURL=RootSiblingsManager.js.map |
@@ -1,22 +0,17 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
var RootController_1 = __importDefault(require("./RootController")); | ||
var RootSiblings_1 = __importDefault(require("./RootSiblings")); | ||
function wrapRootComponent(Root, renderSibling) { | ||
var controller = new RootController_1.default(); | ||
import React from 'react'; | ||
import RootController from './RootController'; | ||
import RootSiblings from './RootSiblings'; | ||
export default function wrapRootComponent(Root, renderSibling) { | ||
const controller = new RootController(); | ||
return { | ||
Root: function (props) { | ||
return (<RootSiblings_1.default controller={controller} renderSibling={renderSibling}> | ||
Root(props) { | ||
return (<RootSiblings controller={controller} renderSibling={renderSibling}> | ||
<Root {...props}/> | ||
</RootSiblings_1.default>); | ||
</RootSiblings>); | ||
}, | ||
manager: { | ||
update: function (id, element, callback) { | ||
update(id, element, callback) { | ||
controller.update(id, element, callback); | ||
}, | ||
destroy: function (id, callback) { | ||
destroy(id, callback) { | ||
controller.destroy(id, callback); | ||
@@ -27,3 +22,2 @@ } | ||
} | ||
exports.default = wrapRootComponent; | ||
//# sourceMappingURL=wrapRootComponent.js.map |
{ | ||
"version": "4.0.0-beta.7", | ||
"version": "4.0.0-beta.8", | ||
"name": "react-native-root-siblings", | ||
@@ -4,0 +4,0 @@ "repository": { |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"target": "es2017", | ||
"strict": true, | ||
@@ -6,0 +5,0 @@ "sourceMap": true, |
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
Sorry, the diff of this file is not supported yet
32168
608