Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
336
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
23
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TransFem.org
Sharkey
Commits
b9577504
Commit
b9577504
authored
3 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
Improve type
parent
36bfaeba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/streaming.ts
+10
-9
10 additions, 9 deletions
src/streaming.ts
src/streaming.types.ts
+11
-2
11 additions, 2 deletions
src/streaming.types.ts
with
21 additions
and
11 deletions
src/streaming.ts
+
10
−
9
View file @
b9577504
...
@@ -3,7 +3,7 @@ import { EventEmitter } from 'eventemitter3';
...
@@ -3,7 +3,7 @@ import { EventEmitter } from 'eventemitter3';
import
ReconnectingWebsocket
from
'
reconnecting-websocket
'
;
import
ReconnectingWebsocket
from
'
reconnecting-websocket
'
;
import
{
stringify
}
from
'
querystring
'
;
import
{
stringify
}
from
'
querystring
'
;
import
{
markRaw
}
from
'
@vue/reactivity
'
;
import
{
markRaw
}
from
'
@vue/reactivity
'
;
import
{
BroadcasrEvents
,
Channel
Def
}
from
'
./streaming.types
'
;
import
{
BroadcasrEvents
,
Channel
s
}
from
'
./streaming.types
'
;
function
urlQuery
(
obj
:
{}):
string
{
function
urlQuery
(
obj
:
{}):
string
{
return
stringify
(
Object
.
entries
(
obj
)
return
stringify
(
Object
.
entries
(
obj
)
...
@@ -49,7 +49,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
...
@@ -49,7 +49,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
}
}
@
autobind
@
autobind
public
useChannel
<
C
extends
keyof
Channel
Def
>
(
channel
:
C
,
params
?:
any
,
name
?:
string
):
Connection
<
Channel
Def
[
C
][
'
events
'
]
>
{
public
useChannel
<
C
extends
keyof
Channel
s
>
(
channel
:
C
,
params
?:
Channels
[
C
][
'
params
'
]
,
name
?:
string
):
Connection
<
Channel
s
[
C
]
>
{
if
(
params
)
{
if
(
params
)
{
return
this
.
connectToChannel
(
channel
,
params
);
return
this
.
connectToChannel
(
channel
,
params
);
}
else
{
}
else
{
...
@@ -58,7 +58,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
...
@@ -58,7 +58,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
}
}
@
autobind
@
autobind
p
ublic
useSharedConnection
<
C
extends
keyof
Channel
Def
>
(
channel
:
C
,
name
?:
string
):
SharedConnection
<
Channel
Def
[
C
][
'
events
'
]
>
{
p
rivate
useSharedConnection
<
C
extends
keyof
Channel
s
>
(
channel
:
C
,
name
?:
string
):
SharedConnection
<
Channel
s
[
C
]
>
{
let
pool
=
this
.
sharedConnectionPools
.
find
(
p
=>
p
.
channel
===
channel
);
let
pool
=
this
.
sharedConnectionPools
.
find
(
p
=>
p
.
channel
===
channel
);
if
(
pool
==
null
)
{
if
(
pool
==
null
)
{
...
@@ -82,7 +82,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
...
@@ -82,7 +82,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
}
}
@
autobind
@
autobind
p
ublic
connectToChannel
<
C
extends
keyof
Channel
Def
>
(
channel
:
C
,
params
?
:
any
):
NonSharedConnection
<
Channel
Def
[
C
][
'
events
'
]
>
{
p
rivate
connectToChannel
<
C
extends
keyof
Channel
s
>
(
channel
:
C
,
params
:
Channels
[
C
][
'
params
'
]
):
NonSharedConnection
<
Channel
s
[
C
]
>
{
const
connection
=
markRaw
(
new
NonSharedConnection
(
this
,
channel
,
params
));
const
connection
=
markRaw
(
new
NonSharedConnection
(
this
,
channel
,
params
));
this
.
nonSharedConnections
.
push
(
connection
);
this
.
nonSharedConnections
.
push
(
connection
);
return
connection
;
return
connection
;
...
@@ -177,6 +177,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
...
@@ -177,6 +177,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
let
idCounter
=
0
;
let
idCounter
=
0
;
// TODO: これらのクラスを Stream クラスの内部クラスにすれば余計なメンバをpublicにしないで済むかも?
class
Pool
{
class
Pool
{
public
channel
:
string
;
public
channel
:
string
;
public
id
:
string
;
public
id
:
string
;
...
@@ -246,7 +247,7 @@ class Pool {
...
@@ -246,7 +247,7 @@ class Pool {
}
}
}
}
abstract
class
Connection
<
Events
extends
Record
<
string
,
any
>
=
any
>
extends
EventEmitter
<
E
vents
>
{
abstract
class
Connection
<
Channel
extends
Channels
[
keyof
Channels
]
=
any
>
extends
EventEmitter
<
Channel
[
'
e
vents
'
]
>
{
public
channel
:
string
;
public
channel
:
string
;
protected
stream
:
Stream
;
protected
stream
:
Stream
;
public
abstract
id
:
string
;
public
abstract
id
:
string
;
...
@@ -280,7 +281,7 @@ abstract class Connection<Events extends Record<string, any> = any> extends Even
...
@@ -280,7 +281,7 @@ abstract class Connection<Events extends Record<string, any> = any> extends Even
public
abstract
dispose
():
void
;
public
abstract
dispose
():
void
;
}
}
class
SharedConnection
<
Events
=
any
>
extends
Connection
<
Events
>
{
class
SharedConnection
<
Channel
extends
Channels
[
keyof
Channels
]
=
any
>
extends
Connection
<
Channel
>
{
private
pool
:
Pool
;
private
pool
:
Pool
;
public
get
id
():
string
{
public
get
id
():
string
{
...
@@ -307,11 +308,11 @@ class SharedConnection<Events = any> extends Connection<Events> {
...
@@ -307,11 +308,11 @@ class SharedConnection<Events = any> extends Connection<Events> {
}
}
}
}
class
NonSharedConnection
<
Events
=
any
>
extends
Connection
<
Events
>
{
class
NonSharedConnection
<
Channel
extends
Channels
[
keyof
Channels
]
=
any
>
extends
Connection
<
Channel
>
{
public
id
:
string
;
public
id
:
string
;
protected
params
:
any
;
protected
params
:
Channel
[
'
params
'
]
;
constructor
(
stream
:
Stream
,
channel
:
string
,
params
?
:
any
)
{
constructor
(
stream
:
Stream
,
channel
:
string
,
params
:
Channel
[
'
params
'
]
)
{
super
(
stream
,
channel
);
super
(
stream
,
channel
);
this
.
params
=
params
;
this
.
params
=
params
;
...
...
This diff is collapsed.
Click to expand it.
src/streaming.types.ts
+
11
−
2
View file @
b9577504
import
{
CustomEmoji
,
DriveFile
,
MeDetailed
,
MessagingMessage
,
Note
,
Notification
,
PageEvent
,
User
}
from
'
./entities
'
;
import
{
CustomEmoji
,
DriveFile
,
MeDetailed
,
MessagingMessage
,
Note
,
Notification
,
PageEvent
,
User
,
UserGroup
}
from
'
./entities
'
;
export
type
Channel
Def
=
{
export
type
Channel
s
=
{
main
:
{
main
:
{
params
:
null
;
events
:
{
events
:
{
notification
:
(
payload
:
Notification
)
=>
void
;
notification
:
(
payload
:
Notification
)
=>
void
;
mention
:
(
payload
:
Note
)
=>
void
;
mention
:
(
payload
:
Note
)
=>
void
;
...
@@ -30,26 +31,34 @@ export type ChannelDef = {
...
@@ -30,26 +31,34 @@ export type ChannelDef = {
};
};
};
};
homeTimeline
:
{
homeTimeline
:
{
params
:
null
;
events
:
{
events
:
{
note
:
(
payload
:
Note
)
=>
void
;
note
:
(
payload
:
Note
)
=>
void
;
};
};
};
};
localTimeline
:
{
localTimeline
:
{
params
:
null
;
events
:
{
events
:
{
note
:
(
payload
:
Note
)
=>
void
;
note
:
(
payload
:
Note
)
=>
void
;
};
};
};
};
hybridTimeline
:
{
hybridTimeline
:
{
params
:
null
;
events
:
{
events
:
{
note
:
(
payload
:
Note
)
=>
void
;
note
:
(
payload
:
Note
)
=>
void
;
};
};
};
};
globalTimeline
:
{
globalTimeline
:
{
params
:
null
;
events
:
{
events
:
{
note
:
(
payload
:
Note
)
=>
void
;
note
:
(
payload
:
Note
)
=>
void
;
};
};
};
};
messaging
:
{
messaging
:
{
params
:
{
otherparty
?:
User
[
'
id
'
]
|
null
;
group
?:
UserGroup
[
'
id
'
]
|
null
;
};
events
:
{
events
:
{
message
:
(
payload
:
MessagingMessage
)
=>
void
;
message
:
(
payload
:
MessagingMessage
)
=>
void
;
deleted
:
(
payload
:
MessagingMessage
[
'
id
'
])
=>
void
;
deleted
:
(
payload
:
MessagingMessage
[
'
id
'
])
=>
void
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment