本文整理汇总了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)
}
开发者ID:react-component,项目名称:editor-core,代码行数:29,代码来源:customHTML2Content.ts
示例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);
}, []);
开发者ID:react-component,项目名称:editor-core,代码行数:29,代码来源:customHTML2Content.ts
示例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');
});
开发者ID:AntanasBarauskas,项目名称:immutable-js,代码行数:10,代码来源:Repeat.ts
示例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)
}
}
开发者ID:socoolxin,项目名称:battle-city,代码行数:26,代码来源:MapRecord.ts
示例5: Repeat
const repFlat = (s: List<string>, n: number): any => Repeat(s, n).flatten().take(n);
开发者ID:sprengerjo,项目名称:katas_js,代码行数:1,代码来源:fizzbuzz.ts
示例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,
/** 即将开始的关卡的名称 */
开发者ID:socoolxin,项目名称:battle-city,代码行数:31,代码来源:game.ts
示例7: unwind
static unwind(botGroupConfig: BotGroupConfig) {
return Repeat(botGroupConfig.tankLevel, botGroupConfig.count)
}
开发者ID:socoolxin,项目名称:battle-city,代码行数:3,代码来源:StageConfig.ts
示例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)
//.........这里部分代码省略.........
开发者ID:socoolxin,项目名称:battle-city,代码行数:101,代码来源:StageConfig.ts
注:本文中的Immutable.Repeat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论