mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
reimplement watchTimeline
prop
This commit is contained in:
parent
17af847d32
commit
59b4603915
@ -39,6 +39,17 @@ export class PostsListsComponent extends React.Component {
|
|||||||
viewRef = this.props.innerRef
|
viewRef = this.props.innerRef
|
||||||
|
|
||||||
timelineWsEvents = {
|
timelineWsEvents = {
|
||||||
|
"feed.new": (data) => {
|
||||||
|
console.log("New feed => ", data)
|
||||||
|
|
||||||
|
if (!this.state.realtimeUpdates) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
list: [data, ...this.state.list],
|
||||||
|
})
|
||||||
|
},
|
||||||
"post.new": (data) => {
|
"post.new": (data) => {
|
||||||
console.log("New post => ", data)
|
console.log("New post => ", data)
|
||||||
|
|
||||||
@ -160,9 +171,17 @@ export class PostsListsComponent extends React.Component {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (this.props.watchTimeline) {
|
if (this.props.watchTimeline) {
|
||||||
Object.entries(this.timelineWsEvents).forEach(([event, callback]) => {
|
if (!Array.isArray(this.props.watchTimeline)) {
|
||||||
app.cores.api.listenEvent(event, callback)
|
console.error("watchTimeline prop must be an array")
|
||||||
})
|
} else {
|
||||||
|
this.props.watchTimeline.forEach((event) => {
|
||||||
|
if (typeof this.timelineWsEvents[event] !== "function") {
|
||||||
|
console.error(`The event "${event}" is not defined in the timelineWsEvents object`)
|
||||||
|
}
|
||||||
|
|
||||||
|
app.cores.api.listenEvent(event, this.timelineWsEvents[event])
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log("PostsList mounted", this.viewRef)
|
//console.log("PostsList mounted", this.viewRef)
|
||||||
@ -177,9 +196,17 @@ export class PostsListsComponent extends React.Component {
|
|||||||
|
|
||||||
componentWillUnmount = async () => {
|
componentWillUnmount = async () => {
|
||||||
if (this.props.watchTimeline) {
|
if (this.props.watchTimeline) {
|
||||||
Object.entries(this.timelineWsEvents).forEach(([event, callback]) => {
|
if (!Array.isArray(this.props.watchTimeline)) {
|
||||||
app.cores.api.unlistenEvent(event, callback)
|
console.error("watchTimeline prop must be an array")
|
||||||
})
|
} else {
|
||||||
|
this.props.watchTimeline.forEach((event) => {
|
||||||
|
if (typeof this.timelineWsEvents[event] !== "function") {
|
||||||
|
console.error(`The event "${event}" is not defined in the timelineWsEvents object`)
|
||||||
|
}
|
||||||
|
|
||||||
|
app.cores.api.unlistenEvent(event, this.timelineWsEvents[event])
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.viewRef) {
|
if (this.viewRef) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user