react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / utils / sliceChildren.js
81152 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule sliceChildren9*/1011"use strict";1213var flattenChildren = require('flattenChildren');1415/**16* Slice children that are typically specified as `props.children`. This version17* of slice children ignores empty child components.18*19* @param {*} children The children set to filter.20* @param {number} start The first zero-based index to include in the subset.21* @param {?number} end The non-inclusive last index of the subset.22* @return {object} mirrored array with mapped children23*/24function sliceChildren(children, start, end) {25if (children == null) {26return children;27}2829var slicedChildren = {};30var flattenedMap = flattenChildren(children);31var ii = 0;32for (var key in flattenedMap) {33if (!flattenedMap.hasOwnProperty(key)) {34continue;35}36var child = flattenedMap[key];37if (ii >= start) {38slicedChildren[key] = child;39}40ii++;41if (end != null && ii >= end) {42break;43}44}45return slicedChildren;46}4748module.exports = sliceChildren;495051