David Aurelio ad8a335864 Remove knowledge of fbjs from the packager
Summary:Follow-up to https://github.com/facebook/react-native/pull/5084

This…
- changes all requires within RN to `require('fbjs/lib/…')`
- updates `.flowconfig`
- updates `packager/blacklist.js`
- adapts tests
- removes things from `Libraries/vendor/{core,emitter}` that are also in fbjs
- removes knowledge of `fbjs` from the packager

Closes https://github.com/facebook/react-native/pull/5084

Reviewed By: bestander

Differential Revision: D2926835

fb-gh-sync-id: 2095e22b2f38e032599d1f2601722b3560e8b6e9
shipit-source-id: 2095e22b2f38e032599d1f2601722b3560e8b6e9
2016-03-02 04:28:38 -08:00

92 lines
1.9 KiB
JavaScript

/**
* Copyright (c) 2015, Facebook, Inc. All rights reserved.
*
* @providesModule NavigationTreeNode
* @flow
* @typechecks
*/
'use strict';
var invariant = require('fbjs/lib/invariant');
var immutable = require('immutable');
var {List} = immutable;
/**
* Utility to build a tree of nodes.
* Note that this tree does not perform cyclic redundancy check
* while appending child node.
*/
class NavigationTreeNode {
__parent: ?NavigationTreeNode;
_children: List<NavigationTreeNode>;
_value: any;
constructor(value: any) {
this.__parent = null;
this._children = new List();
this._value = value;
}
getValue(): any {
return this._value;
}
getParent(): ?NavigationTreeNode {
return this.__parent;
}
getChildrenCount(): number {
return this._children.size;
}
getChildAt(index: number): ?NavigationTreeNode {
return index > -1 && index < this._children.size ?
this._children.get(index) :
null;
}
appendChild(child: NavigationTreeNode): void {
if (child.__parent) {
child.__parent.removeChild(child);
}
child.__parent = this;
this._children = this._children.push(child);
}
removeChild(child: NavigationTreeNode): void {
var index = this._children.indexOf(child);
invariant(
index > -1,
'The node to be removed is not a child of this node.'
);
child.__parent = null;
this._children = this._children.splice(index, 1);
}
indexOf(child: NavigationTreeNode): number {
return this._children.indexOf(child);
}
forEach(callback: Function, context: any): void {
this._children.forEach(callback, context);
}
map(callback: Function, context: any): Array<NavigationTreeNode> {
return this._children.map(callback, context).toJS();
}
some(callback: Function, context: any): boolean {
return this._children.some(callback, context);
}
}
module.exports = NavigationTreeNode;