How to use the immutable.Repeat function in immutable

To help you get started, we’ve selected a few immutable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / Webiny / Js / Webiny / Lib / Draft / BasePlugin.js View on Github external
insertionTargetSelection = insertionTargetBlock.getSelectionAfter();
        }

        const fragmentArray = [];

        if (insertData) {
            // creating a new ContentBlock including the entity with data
            // Entity will be created with a specific type, if defined, else will fall back to the ContentBlock type
            const {text, data, entity} = insertData;
            let characterList = Immutable.List();
            type = insertData.type;
            if (entity) {
                currentContentState = currentContentState.createEntity(entity.type || type, entity.mutability, entity.data);
                const entityKey = currentContentState.getLastCreatedEntityKey();
                const charData = Draft.CharacterMetadata.create({entity: entityKey});
                characterList = Immutable.List(Immutable.Repeat(charData, text.length || 1));
            }

            fragmentArray.push(
                new Draft.ContentBlock({
                    key: Draft.genKey(),
                    type,
                    text,
                    data,
                    characterList // eslint-disable-line new-cap
                })
            );
        }

        // new content block so we can continue writing right away after inserting the block
        fragmentArray.push(
            new Draft.ContentBlock({
github icelab / draft-js-ast-importer / src / compiler.js View on Github external
const styles = node[dataSchema.inline.styles]
      const text = node[dataSchema.inline.text]

      // Convert the styles into an OrderedSet
      const style = OrderedSet(
        styles.map((style) => style)
      )

      // Create a List that has the style values for each character
      let charMetadata = CharacterMetadata.create({
        style,
        entity: opts.entityKey || null,
      })

      // We want the styles to apply to the entire range of `text`
      let characterMeta = Repeat(charMetadata, text.length)

      const characterList = characterMeta.toList()

      return {
        text,
        characterList,
      }
    },
  }
github regentmarkets-repo-archive / binary-next-gen / src / _reducers / trades / TradesParamsReducer.js View on Github external
const newTradesCount = action.tradesCount;
            const countDiff = newTradesCount - oldTradesCount;
            const amountDefault = getAmountDefault(root && root.account);

            if (amountDefault !== defaultParams.amountDefault) {
              defaultParams.amount = amountDefault;
              defaultParams.amountDefault = amountDefault;
              state = state.map(s => s.set('amount', amountDefault));
            }

            if (countDiff > 0) {
                const { assetChoices } = action;
                if (assetChoices && assetChoices.length < countDiff) {
                    throw new Error('Not enough asset choices to create more trade');
                }
                const additionalTradeParams = Repeat(fromJS(defaultParams), countDiff);  // eslint-disable-line new-cap

                if (assetChoices) {
                    return state
                        .concat(additionalTradeParams.map((v, i) => v.set('symbol', assetChoices[i])));
                }

                return state.concat(additionalTradeParams);
            }

            if (countDiff < 0) {
                return state.take(newTradesCount);
            }

            return state;
        }
        case UPDATE_TRADE_PARAMS: {
github romanmatiasko / reti-chess / src / js / components / Chessboard.js View on Github external
Seq(placement).flatMap(piece => (
        /^\d$/.test(piece) ? Repeat('-', parseInt(piece, 10)) : piece
      )).toArray() :
github all-of-us / workbench / ui / src / app / cohort-search / charts / charts.component.ts View on Github external
const combinationDataTable = (cleanData: Data): any[] => {
  let raceSet = Set(cleanData.map(race)).toArray().sort();

  raceSet = raceSet.length > 0
    ? raceSet
    : ['Black or African American', 'White', 'Unknown'];

  const headers = ['Gender-Age', ...raceSet];
  const defaultsByRace = Map(List(raceSet).zip(Repeat(0)));

  let data = cleanData
    .groupBy(genderAndAge)
    .sort()
    .map(group => group
      .groupBy(race)
      .map(sumData)
      .toMap()
      .mergeWith((old, _) => old, defaultsByRace)
      .sort()
      .valueSeq()
      .toArray()
    )
    .map((val, key) => [key, ...val])
    .valueSeq()
    .toArray();
github leejaen / react-lz-editor / src / editor / utils / stateFromElement / main.js View on Github external
processText(text: string) {
    let block = this.blockStack.slice(-1)[0];
    let style = block.styleStack.slice(-1)[0];
    let entity = block.entityStack.slice(-1)[0];
    let charMetadata = CharacterMetadata.create({
      style: style,
      entity: entity,
    });
    let seq: CharacterMetaSeq = Repeat(charMetadata, text.length);
    block.textFragments.push({
      text: text,
      characterMeta: seq,
    });
  }
github sstur / react-rte / src / lib / stateFromElement.js View on Github external
processText(text: string) {
    let block = this.blockStack.slice(-1)[0];
    let style = block.styleStack.slice(-1)[0];
    let entity = block.entityStack.slice(-1)[0];
    let charMetadata = CharacterMetadata.create({
      style: style,
      entity: entity,
    });
    block.textFragments.push({
      text: text,
      characterMeta: Repeat(charMetadata, text.length),
    });
  }
github shinima / battle-city / app / types / StageConfig.ts View on Github external
static unwind(botGroupConfig: BotGroupConfig) {
    return Repeat(botGroupConfig.tankLevel, botGroupConfig.count)
  }
github poetic / byob-cms / src / AppLib / formLib / WysiwygWidget.js View on Github external
const contentBlocksArray = linesFromText.map(line => {
      return new ContentBlock({
        key: genKey(),
        type: currentBlockType,
        characterList: new List(Repeat(CharacterMetadata.create(), line.length)),
        text: line,
      });
    });
github sstur / draft-js-utils / packages / draft-js-import-element / src / stateFromElement.js View on Github external
processText(text: string) {
    let block = this.blockStack.slice(-1)[0];
    let style = block.styleStack.slice(-1)[0];
    let entity = block.entityStack.slice(-1)[0];
    let charMetadata = CharacterMetadata.create({
      style: style,
      entity: entity,
    });
    let seq: CharacterMetaSeq = Repeat(charMetadata, text.length);
    block.textFragments.push({
      text: text,
      characterMeta: seq,
    });
  }