• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript core.registerType函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript core.setSingle函数代码示例发布时间:2022-05-28
下一篇:
TypeScript core.bitHas函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap