本文整理匯總了TypeScript中Immutable.Repeat函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript Repeat函數的具體用法?TypeScript Repeat怎麽用?TypeScript Repeat使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Repeat函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: genKey
const createContentBlock = ( blockData: DraftEntityInstance, contentState: ContentState) => {
const {key, type, text, data, inlineStyles, entityData} = blockData;
let blockSpec = {
type: type != null ? type : 'unstyled',
text: text != null ? text : '',
key: key != null ? key : genKey(),
data: null,
characterList: List([]),
};
if (data) {
blockSpec.data = fromJS(data)
}
if (inlineStyles || entityData) {
let entityKey;
if (entityData) {
const {type, mutability, data} = entityData;
contentState.createEntity(type, mutability, data);
entityKey = contentState.getLastCreatedEntityKey();
} else {
entityKey = null
}
const style = OrderedSet(inlineStyles || [])
const charData = CharacterMetadata.create({style, entityKey} as CharacterMetadataConfig)
blockSpec.characterList = List(Repeat(charData, text.length))
}
return new ContentBlock(blockSpec)
}
示例2: ContentBlock
contentBlocks = contentBlocks.reduce(function (contentBlocks, block) {
if (block.getType() !== 'blockquote') {
return contentBlocks.concat(block)
}
const image = JSON.parse(block.getText())
contentState.createEntity('IMAGE-ENTITY', 'IMMUTABLE', image);
const entityKey = contentState.getLastCreatedEntityKey();
const charData = CharacterMetadata.create({ entity: entityKey });
// const blockSpec = Object.assign({ type: 'atomic', text: ' ' }, { entityData })
// const atomicBlock = createContentBlock(blockSpec)
// const spacerBlock = createContentBlock({});
const fragmentArray = [
new ContentBlock({
key: genKey(),
type: 'image-block',
text: ' ',
characterList: List(Repeat(charData, charData.count())),
}),
new ContentBlock({
key: genKey(),
type: 'unstyled',
text: '',
characterList: List(),
}),
];
return contentBlocks.concat(fragmentArray);
}, []);
示例3: it
it('fixed repeat', () => {
var v = Repeat('wtf', 3);
expect(v.size).toBe(3);
expect(v.first()).toBe('wtf');
expect(v.rest().toArray()).toEqual(['wtf','wtf']);
expect(v.last()).toBe('wtf');
expect(v.butLast().toArray()).toEqual(['wtf','wtf']);
expect(v.toArray()).toEqual(['wtf','wtf','wtf']);
expect(v.join()).toEqual('wtf,wtf,wtf');
});
示例4: Record
import { List, Map as IMap, Record, Repeat } from 'immutable'
import { N_MAP } from '../utils/constants'
import EagleRecord from './EagleRecord'
const MapRecordBase = Record({
eagle: new EagleRecord(),
bricks: Repeat(false, N_MAP.BRICK ** 2).toList(),
steels: Repeat(false, N_MAP.STEEL ** 2).toList(),
rivers: Repeat(false, N_MAP.RIVER ** 2).toList(),
snows: Repeat(false, N_MAP.SNOW ** 2).toList(),
forests: Repeat(false, N_MAP.FOREST ** 2).toList(),
restrictedAreas: IMap<AreaId, Rect>(),
})
export default class MapRecord extends MapRecordBase {
static fromJS(object: any) {
return new MapRecord(object)
.update('eagle', EagleRecord.fromJS)
.update('bricks', List)
.update('steels', List)
.update('rivers', List)
.update('snows', List)
.update('forests', List)
.update('restrictedAreas', IMap)
}
}
示例5: Repeat
const repFlat = (s: List<string>, n: number): any => Repeat(s, n).flatten().take(n);
示例6: Map
const emptyTransientKillInfo = Map({
'player-1': Map({
basic: -1,
fast: -1,
power: -1,
armor: -1,
}),
'player-2': Map({
basic: -1,
fast: -1,
power: -1,
armor: -1,
}),
}) as Map<PlayerName, Map<TankLevel, number>>
const defaultRemainingBots = Repeat('basic' as TankLevel, 20).toList()
const defaultPlayerScores = Map<PlayerName, number>([['player-1', 0], ['player-2', 0]])
type GameStatus = 'idle' | 'on' | 'stat' | 'gameover'
const GameRecordBase = Record(
{
/** 遊戲狀態 */
status: 'idle' as GameStatus,
/** 遊戲是否暫停 */
paused: false,
/** 上次進行的關卡名 */
lastStageName: null as string,
/** 當前的關卡名 */
currentStageName: null as string,
/** 即將開始的關卡的名稱 */
示例7: unwind
static unwind(botGroupConfig: BotGroupConfig) {
return Repeat(botGroupConfig.tankLevel, botGroupConfig.count)
}
示例8: parseStageMap
/**
* 解析關卡文件中的地圖配置.
* 地圖配置數據格式為 string[], 數組中每一個string對應地圖中的一行.
* 一行中包含16個item(由一個或多個空格分隔開來), 對應地圖一行的16個block
* item的第一個字符標記了block的類型, 各個字母的含義見上方
* item後續字符(如果存在的話)為十六進製格式, 用來表示該block中哪些部分包含了地圖元素
* 空白 XX
* 磚塊 brick B<n>
* 河流 river R
* 雪地 snow S
* 森林 forest F
* 鋼塊 steel T<n>
* 老鷹 eagle E
*/
static parseStageMap(map: RawStageConfig['map']) {
const bricks = new Set<number>()
const steels = new Set<number>()
const rivers = new Set<number>()
const snows = new Set<number>()
const forests = new Set<number>()
let eaglePos: Point = null
for (let row = 0; row < FIELD_BLOCK_SIZE; row += 1) {
const line = map[row].toLowerCase().split(/ +/)
for (let col = 0; col < FIELD_BLOCK_SIZE; col += 1) {
const item = line[col].trim()
if (item[0] === 'b') {
// brick
const bits = StageConfig.parseBrickBits(item.substring(1))
const brickRow = 4 * row
const brickCol = 4 * col
const N = 52
const part0 = (bits >> 12) & 0xf
part0 & 0b0001 && bricks.add(brickRow * N + brickCol + 0)
part0 & 0b0010 && bricks.add(brickRow * N + brickCol + 1)
part0 & 0b0100 && bricks.add(brickRow * N + brickCol + N)
part0 & 0b1000 && bricks.add(brickRow * N + brickCol + N + 1)
const part1 = (bits >> 8) & 0xf
part1 & 0b0001 && bricks.add(brickRow * N + brickCol + 2 + 0)
part1 & 0b0010 && bricks.add(brickRow * N + brickCol + 2 + 1)
part1 & 0b0100 && bricks.add(brickRow * N + brickCol + 2 + N)
part1 & 0b1000 && bricks.add(brickRow * N + brickCol + 2 + N + 1)
const part2 = (bits >> 4) & 0xf
part2 & 0b0001 && bricks.add((brickRow + 2) * N + brickCol + 0)
part2 & 0b0010 && bricks.add((brickRow + 2) * N + brickCol + 1)
part2 & 0b0100 && bricks.add((brickRow + 2) * N + brickCol + N)
part2 & 0b1000 && bricks.add((brickRow + 2) * N + brickCol + N + 1)
const part3 = (bits >> 0) & 0xf
part3 & 0b0001 && bricks.add((brickRow + 2) * N + brickCol + 2 + 0)
part3 & 0b0010 && bricks.add((brickRow + 2) * N + brickCol + 2 + 1)
part3 & 0b0100 && bricks.add((brickRow + 2) * N + brickCol + 2 + N)
part3 & 0b1000 && bricks.add((brickRow + 2) * N + brickCol + 2 + N + 1)
} else if (item[0] === 't') {
const bits = parseInt(item[1], 16)
DEV.ASSERT && console.assert(0 < bits && bits < 16)
if (bits & 0b0001) {
steels.add(2 * row * 26 + 2 * col)
}
if (bits & 0b0010) {
steels.add(2 * row * 26 + 2 * col + 1)
}
if (bits & 0b0100) {
steels.add((2 * row + 1) * 26 + 2 * col)
}
if (bits & 0b1000) {
steels.add((2 * row + 1) * 26 + 2 * col + 1)
}
} else if (item[0] === 'r') {
rivers.add(row * FIELD_BLOCK_SIZE + col)
} else if (item[0] === 'f') {
forests.add(row * FIELD_BLOCK_SIZE + col)
} else if (item[0] === 's') {
snows.add(row * FIELD_BLOCK_SIZE + col)
} else if (item[0] === 'e') {
if (eaglePos != null) {
throw new Error('Eagle appears more than once')
} else {
eaglePos = {
x: col * BLOCK_SIZE,
y: row * BLOCK_SIZE,
}
}
} else if (item[0] !== 'x') {
throw new Error(`Invalid map at row:${row} col:${col}`)
}
}
}
return new MapRecord({
eagle: eaglePos
? new EagleRecord({
x: eaglePos.x,
y: eaglePos.y,
broken: false,
})
: null,
bricks: Repeat(false, N_MAP.BRICK ** 2)
//.........這裏部分代碼省略.........