immutable#Repeat JavaScript Examples
The following examples show how to use
immutable#Repeat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: edge-container.js From ThreatMapper with Apache License 2.0 | 6 votes |
prepareWaypointsForMotion({ waypoints, isAnimated }) {
// Don't update if the edges are not animated.
if (!isAnimated) return;
// The Motion library requires the number of waypoints to be constant, so we fill in for
// the missing ones by reusing the edge source point, which doesn't affect the edge shape
// because of how the curveBasis interpolation is done.
const waypointsMissing = EDGE_WAYPOINTS_CAP - waypoints.size;
if (waypointsMissing > 0) {
waypoints = Repeat(waypoints.get(0), waypointsMissing).concat(waypoints);
}
this.setState({ waypointsMap: waypointsArrayToMap(waypoints) });
}
Example #2
Source File: customHTML2Content.js From spring-boot-ecommerce with Apache License 2.0 | 6 votes |
createContentBlock = function createContentBlock(blockData, contentState) {
var key = blockData.key,
type = blockData.type,
text = blockData.text,
data = blockData.data,
inlineStyles = blockData.inlineStyles,
entityData = blockData.entityData;
var 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) {
var entityKey = void 0;
if (entityData) {
var _type = entityData.type,
mutability = entityData.mutability,
_data = entityData.data;
contentState.createEntity(_type, mutability, _data);
entityKey = contentState.getLastCreatedEntityKey();
} else {
entityKey = null;
}
var style = OrderedSet(inlineStyles || []);
var charData = CharacterMetadata.create({ style: style, entityKey: entityKey });
blockSpec.characterList = List(Repeat(charData, text.length));
}
return new ContentBlock(blockSpec);
}
Example #3
Source File: customHTML2Content.js From spring-boot-ecommerce with Apache License 2.0 | 5 votes |
// takes HTML string and returns DraftJS ContentState
export default function customHTML2Content(HTML, contentState) {
var tempDoc = new DOMParser().parseFromString(HTML, 'text/html');
// replace all <img /> with <blockquote /> elements
toArray(tempDoc.querySelectorAll('img')).forEach(imgReplacer);
// use DraftJS converter to do initial conversion. I don't provide DOMBuilder and
// blockRenderMap arguments here since it should fall back to its default ones, which are fine
var _convertFromHTML = convertFromHTML(tempDoc.body.innerHTML),
contentBlocks = _convertFromHTML.contentBlocks;
// now replace <blockquote /> ContentBlocks with 'atomic' ones
contentBlocks = contentBlocks.reduce(function (contentBlocks, block) {
if (block.getType() !== 'blockquote') {
return contentBlocks.concat(block);
}
var image = JSON.parse(block.getText());
contentState.createEntity('IMAGE-ENTITY', 'IMMUTABLE', image);
var entityKey = contentState.getLastCreatedEntityKey();
var charData = CharacterMetadata.create({ entity: entityKey });
// const blockSpec = Object.assign({ type: 'atomic', text: ' ' }, { entityData })
// const atomicBlock = createContentBlock(blockSpec)
// const spacerBlock = createContentBlock({});
var 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);
}, []);
// console.log('>> customHTML2Content contentBlocks', contentBlocks);
tempDoc = null;
return BlockMapBuilder.createFromArray(contentBlocks);
}