mirror of
https://github.com/wassname/talk.git
synced 2026-07-13 17:45:56 +08:00
Add some comments
This commit is contained in:
@@ -18,7 +18,10 @@ export default (reaction) => (WrappedComponent) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Global instance counter for each `reaction` type.
|
||||
let instances = 0;
|
||||
|
||||
// Track current subscriptions.
|
||||
let createdSubscription = null;
|
||||
let deletedSubscription = null;
|
||||
|
||||
@@ -148,6 +151,8 @@ export default (reaction) => (WrappedComponent) => {
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
// Start subscriptions when it is first needed.
|
||||
if (instances === 0) {
|
||||
createdSubscription = context.client.subscribe({
|
||||
query: REACTION_CREATED_SUBSCRIPTION,
|
||||
@@ -172,6 +177,7 @@ export default (reaction) => (WrappedComponent) => {
|
||||
instances++;
|
||||
}
|
||||
|
||||
// onReactionCreated handles live updates through the subscriptions.
|
||||
onReactionCreated = ({[`${reaction}ActionCreated`]: action}) => {
|
||||
if (this.props.user && action.user && this.props.user.id === action.user.id) {
|
||||
return;
|
||||
@@ -179,6 +185,7 @@ export default (reaction) => (WrappedComponent) => {
|
||||
addReactionToStore(this.context.client, {action, self: false});
|
||||
};
|
||||
|
||||
// onReactionDeleted handles live updates through the subscriptions.
|
||||
onReactionDeleted = ({[`${reaction}ActionDeleted`]: action}) => {
|
||||
if (this.props.user && action.user && this.props.user.id === action.user.id) {
|
||||
return;
|
||||
@@ -188,6 +195,8 @@ export default (reaction) => (WrappedComponent) => {
|
||||
|
||||
componentWillUnmount() {
|
||||
instances--;
|
||||
|
||||
// End subscriptions when last component will be unmounted.
|
||||
if (instances === 0) {
|
||||
try {
|
||||
createdSubscription.unsubscribe();
|
||||
|
||||
@@ -130,6 +130,8 @@ function getReactionConfig(reaction) {
|
||||
const response = Comments.get.load(item_id).then((comment) => {
|
||||
return Action.create({item_id, item_type: 'COMMENTS', action_type: REACTION})
|
||||
.then((action) => {
|
||||
|
||||
// The comment is needed to allow better filtering e.g. by asset_id.
|
||||
pubsub.publish(`${reaction}ActionCreated`, {action, comment});
|
||||
return Promise.resolve(action);
|
||||
});
|
||||
@@ -140,6 +142,8 @@ function getReactionConfig(reaction) {
|
||||
const response = Action.delete({id})
|
||||
.then((action) => {
|
||||
return Comments.get.load(action.item_id).then((comment) => {
|
||||
|
||||
// The comment is needed to allow better filtering e.g. by asset_id.
|
||||
pubsub.publish(`${reaction}ActionDeleted`, {action, comment});
|
||||
return Promise.resolve(action);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user