本文整理汇总了TypeScript中@ephox/katamari.Future类的典型用法代码示例。如果您正苦于以下问题:TypeScript Future类的具体用法?TypeScript Future怎么用?TypeScript Future使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Future类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
const check = function (label, initial, destination, amount) {
return Future.nu(function (callback) {
let current = initial;
let values = [ current ];
const add = function (val, abort) {
if (val > 100) {
abort('abort');
} else {
current = val;
values = values.concat([ val ]);
}
};
animator.animate(function () {
return current;
}, destination, amount, add, function (s) {
add(s, Fun.identity);
callback({
label,
info: {
current,
values
}
});
}, 2);
});
};
示例2: function
const moveOnlyScroll = function (element, destination) {
return Future.nu(function (callback) {
const getCurrent = Fun.curry(getScrollTop, element);
Attr.set(element, lastScroll, getCurrent());
const update = function (newScroll, abort) {
const previous = DataAttributes.safeParse(element, lastScroll);
// As soon as we detect a scroll value that we didn't set, assume the user
// is scrolling, and abort the scrolling.
if (previous !== element.dom().scrollTop) {
abort(element.dom().scrollTop);
} else {
element.dom().scrollTop = newScroll;
Attr.set(element, lastScroll, newScroll);
}
};
const finish = function (/* dest */) {
element.dom().scrollTop = destination;
Attr.set(element, lastScroll, destination);
callback(destination);
};
// Identify the number of steps based on distance (consistent time)
const distance = Math.abs(destination - getCurrent());
const step = Math.ceil(distance / NUM_TOP_ANIMATION_FRAMES);
animator.animate(getCurrent, destination, step, update, finish, ANIMATION_RATE);
});
};
示例3: createPartialChoiceMenu
fetch: (comp) => {
return Future.nu((callback) => {
return spec.fetch(callback);
}).map((items) => {
return Option.from(createTieredDataFrom(
Merger.deepMerge(
createPartialChoiceMenu(
Id.generate('menu-value'),
items,
(value) => {
spec.onItemAction(comp, value);
},
spec.columns,
spec.presets,
ItemResponse.CLOSE_ON_EXECUTE,
// No colour is ever selected on opening
() => false,
sharedBackstage.providers
),
{
movement: deriveMenuMovement(spec.columns, spec.presets)
}
)
));
});
},
示例4: return
return (comp: AlloyComponent): Future<Option<TieredData>> => {
return Future.nu((callback) => {
return spec.fetch(callback);
}).map((items) => {
return Option.from(createTieredDataFrom(
Merger.deepMerge(
createPartialChoiceMenu(
Id.generate('menu-value'),
items,
(value) => {
spec.onItemAction(getApi(comp), value);
},
spec.columns,
spec.presets,
ItemResponse.CLOSE_ON_EXECUTE,
spec.select.getOr(() => false),
providersBackstage
),
{
movement: deriveMenuMovement(spec.columns, spec.presets),
menuBehaviours: SimpleBehaviours.unnamedEvents(spec.columns !== 'auto' ? [ ] : [
AlloyEvents.runOnAttached((comp, se) => {
detectSize(comp, 4, classForPreset(spec.presets)).each(({ numRows, numColumns }) => {
Keying.setGridSize(comp, numRows, numColumns);
});
})
])
} as TieredMenuTypes.PartialMenuSpec
)
));
});
};
示例5: function
const loadF = function (url) {
return Future.nu(function (resolve) {
load(
url,
Fun.compose(resolve, Fun.constant(Result.value(url))),
Fun.compose(resolve, Fun.constant(Result.error(url)))
);
});
};
示例6:
validate: (input) => {
const inputValue = Representing.getValue(input);
// Consider empty strings valid colours
if (inputValue.length === 0) {
return Future.pure(Result.value(true));
} else {
const span = Element.fromTag('span');
Css.set(span, 'background-color', inputValue);
const res = Css.getRaw(span, 'background-color').fold(
// TODO: Work out what we want to do here.
() => Result.error('blah'),
(_) => Result.value(inputValue)
);
return Future.pure(res);
}
}
示例7: completer
const collect = (editor): Future<ImageDialogInfo> => {
const urlListSanitizer = ListUtils.sanitizer((item) => {
return editor.convertURL(item.value || item.url, 'src');
});
const futureImageList = Future.nu<Option<ListItem[]>>((completer) => {
Utils.createImageList(editor, (imageList) => {
completer(
urlListSanitizer(imageList).map(
(items) => Arr.flatten([
[{ text: 'None', value: '' }],
items
])
)
);
});
});
const classList = ListUtils.sanitize(Settings.getClassList(editor));
const hasAdvTab = Settings.hasAdvTab(editor);
const hasUploadUrl = Settings.hasUploadUrl(editor);
const hasUploadHandler = Settings.hasUploadHandler(editor);
const image = readImageDataFromSelection(editor);
const hasDescription = Settings.hasDescription(editor);
const hasImageTitle = Settings.hasImageTitle(editor);
const hasDimensions = Settings.hasDimensions(editor);
const hasImageCaption = Settings.hasImageCaption(editor);
const url = Settings.getUploadUrl(editor);
const basePath = Settings.getUploadBasePath(editor);
const credentials = Settings.getUploadCredentials(editor);
const handler = Settings.getUploadHandler(editor);
const prependURL: Option<string> = Option.some(Settings.getPrependUrl(editor)).filter(
(preUrl) => Type.isString(preUrl) && preUrl.length > 0);
return futureImageList.map((imageList): ImageDialogInfo => {
return {
image,
imageList,
classList,
hasAdvTab,
hasUploadUrl,
hasUploadHandler,
hasDescription,
hasImageTitle,
hasDimensions,
hasImageCaption,
url,
basePath,
credentials,
handler,
prependURL
};
});
};
示例8: resolve
return Futures.mapM(items, (item: any) => {
return Future.nu((resolve) => {
const blob = item.getAsFile ? item.getAsFile() : item;
const reader = new window.FileReader();
reader.onload = () => {
resolve({
blob,
uri: reader.result
});
};
reader.readAsDataURL(blob);
});
});
示例9: makeDialog
const open = function (editor: Editor) {
const data = collectData(editor);
data.map((info) => {
const onSubmit = handleSubmit(editor, info, Settings.assumeExternalTargets(editor.settings));
return makeDialog(info, onSubmit, editor.settings);
}).get((spec) => {
editor.windowManager.open(spec);
});
};