本文整理汇总了TypeScript中@statecraft/core.registerType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript registerType函数的具体用法?TypeScript registerType怎么用?TypeScript registerType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了registerType函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: registerType
// This runs in the browser and is compiled to public/bundle.js
import {I, otDoc, registerType, subValues} from '@statecraft/core'
import {connectToWS, reconnectingclient} from '@statecraft/net'
import {type as texttype, TextOp} from 'ot-text-unicode'
registerType(texttype)
declare const config: {
key: string,
initialValue: string | null,
initialVersions: (number[] | null)[],
}
// document.body.appendChild(html`<h1>oh hi</h1>`)
const elem = document.getElementById('content') as HTMLTextAreaElement | null
if (elem == null) throw Error('Could not find document #content div')
// *** Text editing operations
interface TextCtx {
insert(pos: number, val: string): void
remove(pos: number, len: number): void
}
const id = <T>(x: T) => x
let prevvalue: string = ''
// Replace the content of the text area with newText, and transform the
开发者ID:josephg,项目名称:statecraft,代码行数:31,代码来源:editor.ts
示例2: registerType
import {I, stores, rmKV, setKV, subValues, registerType, resultTypes, catchupStateMachine} from '@statecraft/core'
import {wrapWebSocket, connectMux, BothMsg, tcpserver} from '@statecraft/net'
import express from 'express'
import WebSocket from 'ws'
import http from 'http'
// import kvMem from '../../lib/stores/kvmem'
import State from './state'
import {type as jsonType, JSONOp} from 'ot-json1'
registerType(jsonType)
const {kvmem} = stores
process.on('unhandledRejection', err => {
console.error((err as any).stack)
process.exit(1)
})
;(async () => {
// The store is a kv store mapping from client ID (incrementing numbers) => latest position.
const store = await kvmem<State>()
const app = express()
app.use(express.static(`${__dirname}/public`))
const server = http.createServer(app)
const wss = new WebSocket.Server({server})
let nextId = 1000
wss.on('connection', async (socket, req) => {
开发者ID:josephg,项目名称:statecraft,代码行数:31,代码来源:server.ts
示例3: registerType
import choo, { IState } from 'choo'
import html from 'choo/html'
import {I, subValues, subResults, sel, registerType, queryTypes, bitHas, version} from '@statecraft/core'
import {reconnectingclient, connectToWS} from '@statecraft/net'
import {type as texttype} from 'ot-text-unicode'
import {type as jsontype} from 'ot-json1'
registerType(texttype)
registerType(jsontype)
type Op = {v: (I.Version | null)[], op?: I.Op<any>, replace?: any}
type Ops = Op[]
interface State extends IState {
sources: I.Source[]
uid: string,
versions: I.FullVersion
data: any
// selectedKey?: string
connectionStatus: string
prefer: 'pre' | 'html'
opsForKey: Map<string, Ops>
}
const hex = (v: Uint8Array): string => (
Array.prototype.map.call(v, (x: number) => ('00' + x.toString(16)).slice(-2)).join('')
)
开发者ID:josephg,项目名称:statecraft,代码行数:30,代码来源:client.ts
注:本文中的@statecraft/core.registerType函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论