本文整理汇总了TypeScript中ramda.take函数的典型用法代码示例。如果您正苦于以下问题:TypeScript take函数的具体用法?TypeScript take怎么用?TypeScript take使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了take函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: createLastPosition
function* createLastPosition({
payload
}: ActionType<typeof lastPositionsCreator.createLastPosition>): SagaIterator {
try {
const {lastPositions = []}: LocalStorage = yield call(getLocalStorage)
if (payload.index <= lastPositions.length) {
if (lastPositions[payload.index] && lastPositions[payload.index].id === payload.id) {
return
}
const updatedLastPositions = [
...R.take(payload.index, lastPositions),
{
id: payload.id,
scrollTop: 0
}
]
yield call(setLocalStorage, {
lastPositions: updatedLastPositions
})
}
} catch (err) {
console.error(err)
}
}
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:27,代码来源:saga.ts
示例2: test
test('should remove tree and its child trees if cannot get that tree', () => {
for (let i = 1; i < correlatedBookmarkTrees.length; i += 1) {
const clonedGenerator = generator.clone()
const partiallyUnrelatedBookmarkTrees = R.set(R.lensIndex(i), null, correlatedBookmarkTrees)
expect(clonedGenerator.next(partiallyUnrelatedBookmarkTrees).value).toEqual(
R.take(i, partiallyUnrelatedBookmarkTrees)
)
expect(clonedGenerator.next().done).toBe(true)
}
})
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:12,代码来源:getters.test.ts
示例3: describe
describe('getBookmarkTrees', () => {
// limit to 4 trees, and set parentId to previous tree id
const correlatedBookmarkTrees = R.take(4, bookmarkTrees).reduce(
(acc: Array<BookmarkTree>, bookmarkTree) => {
if (!acc.length) return [bookmarkTree]
const prevBookmarkTree = R.last(acc)
if (!prevBookmarkTree) throw new Error('prevBookmarkTree must exist')
const updatedBookmarkTree = R.set(
R.lensPath(['parent', 'parentId']),
prevBookmarkTree.parent.id,
bookmarkTree
)
return [...acc, updatedBookmarkTree]
},
[]
)
const getRestTreeIds = (trees: Array<BookmarkTree>) => R.tail(trees).map((tree) => tree.parent.id)
const options = optionsFixture
const restTreeIds = getRestTreeIds(correlatedBookmarkTrees)
const generator = cloneableGenerator(getters.getBookmarkTrees)(restTreeIds, options)
expect(generator.next().value).toEqual(
all([
call(getters.getFirstBookmarkTree, options),
...R.map((id) => call(getters.tryGetBookmarkTree, id), restTreeIds)
])
)
test('should get all trees', () => {
const clonedGenerator = generator.clone()
expect(clonedGenerator.next(correlatedBookmarkTrees).value).toEqual(correlatedBookmarkTrees)
expect(clonedGenerator.next().done).toBe(true)
})
test('should remove tree and its child trees if cannot get that tree', () => {
for (let i = 1; i < correlatedBookmarkTrees.length; i += 1) {
const clonedGenerator = generator.clone()
const partiallyUnrelatedBookmarkTrees = R.set(R.lensIndex(i), null, correlatedBookmarkTrees)
expect(clonedGenerator.next(partiallyUnrelatedBookmarkTrees).value).toEqual(
R.take(i, partiallyUnrelatedBookmarkTrees)
)
expect(clonedGenerator.next().done).toBe(true)
}
})
})
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:51,代码来源:getters.test.ts
示例4: getVocabulary
public getVocabulary(id: string): string[] {
if (this.getId() === id) {
return this.getNewVocabulary();
}
const nodesUntilId = takeWhile(
found => !found,
map(child => child.findEntity(id), this.getChildren())
);
const previousChildren = take(nodesUntilId.length + 1, this.getChildren());
return concat(
flatten<string>(map(node => node.getVocabulary(id), previousChildren)),
this.getNewVocabulary()
);
}
开发者ID:serlo-org,项目名称:serlo-abc,代码行数:16,代码来源:InternalNode.ts
示例5: removeLastPosition
function* removeLastPosition({
payload
}: ActionType<typeof lastPositionsCreator.removeLastPosition>): SagaIterator {
try {
const {lastPositions = []}: LocalStorage = yield call(getLocalStorage)
if (payload.index <= lastPositions.length - 1) {
const updatedLastPositions = R.take(payload.index, lastPositions)
yield call(setLocalStorage, {
lastPositions: updatedLastPositions
})
}
} catch (err) {
console.error(err)
}
}
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:17,代码来源:saga.ts
示例6: apply
export default function apply(config: Config) {
let client = config.client;
let command = config.commands.apply;
let migrations = listMigrations(config.files.directory);
let journal = readJournal(client.name, client.config, client.journalTable);
let states = Promise.join(migrations, journal, getMigrationStates)
let applicableIDs = states
.then(R.filter(isApplicable))
.then(ss => R.map(s => s.migrationID, ss));
let toApplyIDs: Promise<string[]>;
if (command.pending) {
toApplyIDs = applicableIDs;
} else if (command.id) {
toApplyIDs = applicableIDs.then(R.filter(id => id === command.id));
} else if (command.to) {
toApplyIDs = applicableIDs.then(R.filter(id => id <= command.to));
} else if (command.number) {
toApplyIDs = applicableIDs.then(R.take(command.number));
} else {
toApplyIDs = Promise.resolve([]);
}
let toApply = Promise.join(migrations, toApplyIDs, (ms, ids) =>
R.filter(m => R.contains(m.id, ids), ms)
);
let apply = toApply.then(ms =>
applyFunction(command.method)(
client.name, client.config, client.journalTable, ms
)
);
let previousEntry = journal.then(es => R.last(es));
let newEntries = Promise.join(previousEntry, apply, (prev, es) =>
prev ? R.filter(e => e.timestamp > prev.timestamp, es) : apply
);
return newEntries
.then(R.map(formatJournalEntry))
.then(R.join(''));
}
开发者ID:programble,项目名称:careen,代码行数:44,代码来源:apply.ts
示例7: getLetters
public getLetters(id: string): string[] {
const newLetterArr: string[] = this.getNewLetter()
? ([this.getNewLetter()] as string[])
: [];
if (this.getId() === id) {
return newLetterArr;
}
const nodesUntilId = takeWhile(
found => !found,
map(child => child.findEntity(id), this.getChildren())
);
const previousChildren = take(nodesUntilId.length + 1, this.getChildren());
return concat(
flatten<string>(map(node => node.getLetters(id), previousChildren)),
newLetterArr
);
}
开发者ID:serlo-org,项目名称:serlo-abc,代码行数:19,代码来源:InternalNode.ts
示例8: revert
export default function revert(config: Config) {
let client = config.client;
let command = config.commands.revert;
let migrations = listMigrations(config.files.directory);
let journal = readJournal(client.name, client.config, client.journalTable);
let states = Promise.join(migrations, journal, getMigrationStates);
let revertableIDs = states
.then(R.filter(isRevertable))
.then(ss => R.map(s => s.migrationID, ss));
let toRevertIDs: Promise<string[]>;
if (command.id) {
toRevertIDs = revertableIDs.then(R.filter(id => id === command.id));
} else if (command.to) {
toRevertIDs = revertableIDs.then(R.filter(id => id > command.to));
} else if (command.number) {
toRevertIDs = revertableIDs.then(R.reverse).then(R.take(command.number));
} else {
toRevertIDs = Promise.resolve([]);
}
let toRevert = Promise.join(migrations, toRevertIDs, (ms, ids) =>
R.filter(m => R.contains(m.id, ids), R.reverse(ms))
);
let revert = toRevert.then(ms =>
revertFunction(command.method)(
client.name, client.config, client.journalTable, ms
)
);
let previousEntry = journal.then(es => R.last(es));
let newEntries = Promise.join(previousEntry, revert, (prev, es) =>
R.filter(e => e.timestamp > prev.timestamp, es)
);
return newEntries
.then(R.map(formatJournalEntry))
.then(R.join(''));
}
开发者ID:programble,项目名称:careen,代码行数:42,代码来源:revert.ts
示例9: take
updateRight<Event[], Event[]>((prevEvents, events) => take(100, events)),
开发者ID:displague,项目名称:manager,代码行数:1,代码来源:event.helpers.ts
示例10: equals
const isSpare = rolls => equals(10, sum(take(2, rolls)));
开发者ID:sprengerjo,项目名称:katas_js,代码行数:1,代码来源:bowling_score_calculator.ts
注:本文中的ramda.take函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论