Skip to content

Commit

Permalink
UClarify text
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Feb 16, 2024
1 parent 5bc57cf commit ce27289
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion guide/concepts/subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ end

</details>

After sending initial state, the server needs to mark all action related to this channel in `resend` callback. Logux will resend these actions to all clients subscribed to this channel.
After sending initial state, the server needs to know what actions are connected with this channel. You can set channels for action in `resend` callback. Logux will resend these actions to all clients subscribed to this channel.

For instance, we are marking all `users/add` actions as actions inside `users/:id` channel to send them too all users subscribed to that channel.

<details open><summary>Node.js</summary>

Expand Down

6 comments on commit ce27289

@nichoth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional words.

So the return value is the name of a channel, and any clients that are subscribed to that channel name will get the action that we are processing server-side; is that right?

server.type('users/add', {
  // …
  resend (ctx, action, meta) {
    return `users/${ action.userId }`
  },
  // …
})

I will try making some statements to see if I understand correctly. In the example code, we will re-send this action to any user subscribed to the channel 'users/${userId}'? That way anyone subscribed to the channel of users/${userId} will get the action, and can re-compute the state client-side, from the action.

The server in this way acts as a 'hub' in a fan-out type of message distribution, re-sending the message to anyone else that cares about it.


One other question — the example in the docs shows resend as a parameter to server.type method, but should this be server.channel?

@ai
Copy link
Member Author

@ai ai commented on ce27289 Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the return value is the name of a channel, and any clients that are subscribed to that channel name will get the action that we are processing server-side; is that right?

Yes

In the example code, we will re-send this action to any user subscribed to the channel 'users/${userId}'? That way anyone subscribed to the channel of users/${userId} will get the action, and can re-compute the state client-side, from the action.

Yes

The server in this way acts as a 'hub' in a fan-out type of message distribution, re-sending the message to anyone else that cares about it.

Yes

One other question — the example in the docs shows resend as a parameter to server.type method, but should this be server.channel?

No. server.type() is a setting for each action. And you set channels for action in resend. resend() from example will be called only for actions like { type: 'users/add', … }

@nichoth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, that is clear.

@nichoth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One part that was confusing to me was "marking all users/add actions as actions"

For instance, we are marking all users/add actions as actions inside users/:id channel to send them too all users subscribed to that channel.

A possible different wording:

For instance, here we are saying that all users/add actions should be broadcast to all clients subscribed to the users/:id channel, where :id comes from the action data.

@ai
Copy link
Member Author

@ai ai commented on ce27289 Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A possible different wording:

I like it. Can you send PR to save your name in the project history?

@nichoth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; PR sent.

Please sign in to comment.