本文整理汇总了TypeScript中mithril/stream.stream函数的典型用法代码示例。如果您正苦于以下问题:TypeScript stream函数的具体用法?TypeScript stream怎么用?TypeScript stream使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
protected constructor(name: string, type: RoleType, attributes: T, errors: Errors = new Errors()) {
super();
ValidatableMixin.call(this);
this.type = stream(type);
this.name = stream(name);
this.attributes = stream(attributes);
this.errors(errors);
this.validatePresenceOf("name");
this.validateFormatOf("name",
new RegExp("^[-a-zA-Z0-9_][-a-zA-Z0-9_.]*$"),
{message: "Invalid Id. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period)."});
this.validateMaxLength("name", 255, {message: "The maximum allowed length is 255 characters."});
}
示例2: FollowersCtrl
export default function FollowersCtrl(userId: string): IRelationCtrl {
socket.createDefault()
const related: Mithril.Stream<Related[]> = stream([])
const paginator: Mithril.Stream<Paginator<Related> | undefined> = stream(undefined)
const isLoadingNextPage = stream(false)
function loadNextPage(page: number) {
isLoadingNextPage(true)
xhr.followers(userId, page)
.then(data => {
isLoadingNextPage(false)
paginator(data.paginator)
related(related().concat(data.paginator.currentPageResults))
redraw()
})
.catch(handleXhrError)
redraw()
}
xhr.followers(userId, 1, true)
.then(data => {
paginator(data.paginator)
related(data.paginator.currentPageResults)
redraw()
})
.catch(handleXhrError)
function setNewUserState(obj: Related, newData: xhr.RelationActionResult) {
obj.relation = newData.following
redraw()
}
return {
related,
loadNextPage,
isLoadingNextPage,
toggleFollowing: (obj: Related) => {
if (obj.relation) xhr.unfollow(obj.user).then(d => setNewUserState(obj, d))
else xhr.follow(obj.user).then(d => setNewUserState(obj, d))
},
challenge(id: string) {
challengeForm.open(id)
},
paginator
}
}
示例3: constructor
constructor(url: string,
autoUpdate: boolean,
name: string,
destination: string,
checkExternals: boolean,
username: string,
password: string,
encryptedPassword: string,
filter: Filter,
invertFilter: boolean,
errors: { [key: string]: string[] } = {}) {
super(url, autoUpdate, name, destination, filter, invertFilter, errors);
this.checkExternals = stream(checkExternals);
this.username = stream(username);
this.password = stream(plainOrCipherValue({plainText: password, cipherText: encryptedPassword}));
}
示例4: oninit
export default function oninit(userId: string) {
const user: Mithril.Stream<UserFullProfile | undefined> = stream(undefined)
function setNewUserState(newData: Partial<UserFullProfile>) {
Object.assign(user(), newData)
redraw()
}
xhr.user(userId)
.then(data => {
user(data)
redraw()
})
.then(session.refresh)
.catch(utils.handleXhrError)
return {
user,
isMe: () => session.getUserId() === userId,
toggleFollowing() {
const u = user()
if (u && u.following) xhr.unfollow(u.id).then(setNewUserState)
else if (u) xhr.follow(u.id).then(setNewUserState)
},
toggleBlocking() {
const u = user()
if (u && u.blocking) xhr.unblock(u.id).then(setNewUserState)
else if (u) xhr.block(u.id).then(setNewUserState)
},
goToGames() {
const u = user()
if (u) {
router.set(`/@/${u.id}/games`)
}
},
goToUserTV() {
const u = user()
if (u) {
router.set(`/@/${u.id}/tv`)
}
},
challenge() {
const u = user()
if (u) {
challengeForm.open(u.id)
}
},
composeMessage() {
const u = user()
if (u) {
router.set(`/inbox/new/${u.id}`)
}
}
}
}
示例5: ImporterCtrl
export default function ImporterCtrl(): IImporterCtrl {
const importing = stream(false)
function submitOnline(pgn: string, analyse: boolean): Promise<OnlineGameData> {
const data: {[i: string]: string } = { pgn }
if (analyse) data.analyse = '1'
return fetchJSON('/import', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'Accept': 'application/vnd.lichess.v' + globalConfig.apiVersion + '+json'
},
body: serializeQueryParameters(data)
}, true)
}
window.addEventListener('keyboardDidHide', helper.onKeyboardHide)
window.addEventListener('keyboardDidShow', helper.onKeyboardShow)
return {
importGame(pgn: string) {
importing(true)
redraw()
submitOnline(pgn, settings.importer.analyse())
.then(data => {
router.set(`/analyse/online${data.url.round}`)
})
.catch(err => {
importing(false)
redraw()
console.error(err)
handleXhrError(err)
})
},
importing
}
}
示例6: constructor
constructor(profiles: ElasticAgentProfile[]) {
this.profiles = stream(profiles);
}
示例7: constructor
constructor(variables: Variable[]) {
this.variables = stream(variables);
}