本文整理汇总了TypeScript中slate-plain-serializer.serialize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript serialize函数的具体用法?TypeScript serialize怎么用?TypeScript serialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serialize函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('adds closing braces outside a selector', () => {
const change = Plain.deserialize('sumrate(metric{namespace="dev", cluster="c1"}[2m])').change();
let event;
change.move(3);
event = new window.KeyboardEvent('keydown', { key: '(' });
handler(event, change);
expect(Plain.serialize(change.value)).toEqual('sum(rate(metric{namespace="dev", cluster="c1"}[2m]))');
});
示例2: it
it('removes closing brace when opening brace is removed', () => {
const change = Plain.deserialize('time()').change();
let event;
change.move(5);
event = new window.KeyboardEvent('keydown', { key: 'Backspace' });
handler(event, change);
expect(Plain.serialize(change.value)).toEqual('time');
});
示例3: it
it('does not change the empty value', () => {
const change = Plain.deserialize('').change();
const event = new window.KeyboardEvent('keydown', {
key: 'k',
ctrlKey: true,
});
handler(event, change);
expect(Plain.serialize(change.value)).toEqual('');
});
示例4: it
it('adds closing braces around the following value only', () => {
const change = Plain.deserialize('foo bar ugh').change();
let event;
event = new window.KeyboardEvent('keydown', { key: '(' });
handler(event, change);
expect(Plain.serialize(change.value)).toEqual('(foo) bar ugh');
// Wrap bar
change.move(5);
event = new window.KeyboardEvent('keydown', { key: '(' });
handler(event, change);
expect(Plain.serialize(change.value)).toEqual('(foo) (bar) ugh');
// Create empty parens after (bar)
change.move(4);
event = new window.KeyboardEvent('keydown', { key: '(' });
handler(event, change);
expect(Plain.serialize(change.value)).toEqual('(foo) (bar)() ugh');
});
示例5:
import Plain from "slate-plain-serializer";
import { Value } from "slate";
const val = Value.create();
const serialized = Plain.serialize(val);
const deserialized = Plain.deserialize(serialized);
示例6: validateChanges
export async function validateChanges(
articleId: number,
componentState: ArticleControllerState,
displayConfirm: DisplayConfirm,
): Promise<
| {
invalid: true;
msg?: string;
}
| {
invalid: false;
plainMarkdown: any; // This is actually Slate.Value but have some typing config problems we should fix
processedAuthors: number[] | null;
processedTags: {}[] | null;
}
> {
const falcorData = componentState.data.articles.byId[articleId];
let processedAuthors: number[] | null = componentState.authors.map(
author => author.id,
);
// Check that all authors are unique
if (_.uniq(processedAuthors).length !== processedAuthors.length) {
return {
invalid: true,
msg:
"You have duplicate authors, as this shouldn't be able" +
' to happen, please contact developers. And if you know all the actions' +
' you did previously to this and can reproduce them that would be of' +
' great help. The save has been cancelled',
};
}
// Check that there wasn't already authors and they deleted all of them
if (
processedAuthors.length === 0 &&
(falcorData.authors &&
parseFalcorPseudoArray(falcorData.authors).length > 0)
) {
return {
invalid: true,
msg:
"Sorry, because of some non-trivial issues we currently don't have" +
' deleting every single author implemented.' +
" You hopefully shouldn't need this function either." +
' Please re-add an author to be able to save',
};
}
// Copy the array of tags.
let processedTags: {}[] | null = _.clone(componentState.tags);
if (_.uniqWith(processedTags, _.isEqual).length !== processedTags.length) {
return {
invalid: true,
msg:
"You have duplicate tags, as this shouldn't be able" +
' to happen, please contact developers. And if you know all the actions' +
' you did previously to this and can reproduce them that would be of' +
' great help. The save has been cancelled',
};
}
// Check the special case of someone trying to reassign a category as none
if (
componentState.category === null &&
_.get(falcorData, 'category.id', null) !== null
) {
return {
invalid: true,
msg:
'Save cancelled, you cannot reset a category to none.' +
' If you wish to have this feature added, speak to the developers',
};
}
if (
componentState.imageUrl.length > 4 &&
componentState.imageUrl.substr(0, 5) !== 'https'
) {
const shouldContinue = await displayConfirm(
'You are saving an image without using https. ' +
'This can be correct in a few cases but is mostly not. Are you sure ' +
'that you wish to continue saving?',
);
if (!shouldContinue) {
return { invalid: true };
}
}
if (
processedAuthors.length === 0 &&
(!falcorData.authors || Object.keys(falcorData.authors).length === 0)
) {
// Indicate that we won't update authors as there were none before and none were added
processedAuthors = null;
}
const plainMarkdown = Plain.serialize(componentState.markdown);
if (
processedTags.length === 0 &&
//.........这里部分代码省略.........