Merge pull request #376 from fson/yevent-target-type

Add more accurate typing for YEvent.target
This commit is contained in:
Kevin Jahns 2022-03-02 13:18:00 +01:00 committed by GitHub
commit 9f1548204a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 10 deletions

View File

@ -39,7 +39,7 @@ export const YXmlTextRefID = 6
*/
export class ContentType {
/**
* @param {AbstractType<YEvent>} type
* @param {AbstractType<any>} type
*/
constructor (type) {
/**

View File

@ -278,7 +278,7 @@ export class AbstractType {
this._eH = createEventHandler()
/**
* Deep event handlers
* @type {EventHandler<Array<YEvent>,Transaction>}
* @type {EventHandler<Array<YEvent<any>>,Transaction>}
*/
this._dEH = createEventHandler()
/**
@ -364,7 +364,7 @@ export class AbstractType {
/**
* Observe all events that are created by this type and its children.
*
* @param {function(Array<YEvent>,Transaction):void} f Observer function
* @param {function(Array<YEvent<any>>,Transaction):void} f Observer function
*/
observeDeep (f) {
addEventHandlerListener(this._dEH, f)
@ -382,7 +382,7 @@ export class AbstractType {
/**
* Unregister an observer function.
*
* @param {function(Array<YEvent>,Transaction):void} f Observer function
* @param {function(Array<YEvent<any>>,Transaction):void} f Observer function
*/
unobserveDeep (f) {
removeEventHandlerListener(this._dEH, f)

View File

@ -23,6 +23,7 @@ import { typeListSlice } from './AbstractType.js'
/**
* Event that describes the changes on a YArray
* @template T
* @extends YEvent<YArray<T>>
*/
export class YArrayEvent extends YEvent {
/**

View File

@ -21,6 +21,7 @@ import * as iterator from 'lib0/iterator'
/**
* @template T
* @extends YEvent<YMap<T>>
* Event that describes the changes on a YMap.
*/
export class YMapEvent extends YEvent {

View File

@ -512,6 +512,7 @@ const deleteText = (transaction, currPos, length) => {
*/
/**
* @extends YEvent<YText>
* Event that describes the changes on a YText type.
*/
export class YTextEvent extends YEvent {

View File

@ -5,6 +5,7 @@ import {
} from '../internals.js'
/**
* @extends YEvent<YXmlElement|YXmlText|YXmlFragment>
* An Event that describes changes on a YXml Element or Yxml Fragment
*/
export class YXmlEvent extends YEvent {

View File

@ -48,7 +48,7 @@ export class Doc extends Observable {
this.guid = guid
this.collectionid = collectionid
/**
* @type {Map<string, AbstractType<YEvent>>}
* @type {Map<string, AbstractType<YEvent<any>>>}
*/
this.share = new Map()
this.store = new StructStore()

View File

@ -75,13 +75,13 @@ export class Transaction {
* All types that were directly modified (property added or child
* inserted/deleted). New types are not included in this Set.
* Maps from type to parentSubs (`item.parentSub = null` for YArray)
* @type {Map<AbstractType<YEvent>,Set<String|null>>}
* @type {Map<AbstractType<YEvent<any>>,Set<String|null>>}
*/
this.changed = new Map()
/**
* Stores the events for the types that observe also child elements.
* It is mainly used by `observeDeep`.
* @type {Map<AbstractType<YEvent>,Array<YEvent>>}
* @type {Map<AbstractType<YEvent<any>>,Array<YEvent<any>>>}
*/
this.changedParentTypes = new Map()
/**
@ -148,7 +148,7 @@ export const nextID = transaction => {
* did not change, it was just added and we should not fire events for `type`.
*
* @param {Transaction} transaction
* @param {AbstractType<YEvent>} type
* @param {AbstractType<YEvent<any>>} type
* @param {string|null} parentSub
*/
export const addChangedTypeToTransaction = (transaction, type, parentSub) => {

View File

@ -8,17 +8,18 @@ import * as set from 'lib0/set'
import * as array from 'lib0/array'
/**
* @template {AbstractType<any>} T
* YEvent describes the changes on a YType.
*/
export class YEvent {
/**
* @param {AbstractType<any>} target The changed type.
* @param {T} target The changed type.
* @param {Transaction} transaction
*/
constructor (target, transaction) {
/**
* The type on which this event was created on.
* @type {AbstractType<any>}
* @type {T}
*/
this.target = target
/**