logux_rails icon indicating copy to clipboard operation
logux_rails copied to clipboard

Strange behaviour

Open ai opened this issue 7 years ago • 3 comments

I am adding prices channel to Amplifr. Gem force me to have some code for the channel. So I created app/logux/channels/prices.rb with:

module Channels
  class Prices < Channels::Base
  end
end

But gem start to write this response on subscription:

{
  "version": 0,
  "password": "secret",
  "commands": [
    [
      "action",
      1,
      {
        "nodeIds": [
          "380:TMt6iOHX"
        ]
      }
    ],
    [
      "action",
      2,
      {
        "nodeIds": [
          "380:TMt6iOHX"
        ]
      }
    ]
  ]
}

Seems like without initial_data, gem anyway send action command.

ai avatar Oct 03 '18 17:10 ai

I think current initial_data API should be changed. It will better and more clear if a user will call Logux.add_batch manually. Right now there is no way to set meta.

ai avatar Oct 03 '18 17:10 ai

Let's split this task into 2. The first one strange behavior occurs because of this: https://github.com/logux/logux_rails/blob/master/lib/logux/channel_controller.rb#L9. I don't know what it is; Correct me if I wrong, but I think we can replace it with NotImplementedError.

The second one: initial_data it's just syntax sugar, you can redefine method subscribe and add actions manually: https://github.com/logux/logux_rails/blob/master/lib/logux/channel_controller.rb#L5 Also, you can redefine initial meta: https://github.com/logux/logux_rails/blob/master/lib/logux/channel_controller.rb#L13

wilddima avatar Nov 27 '18 12:11 wilddima

The second one: initial_data it's just syntax sugar, you can redefine method subscribe and add actions manually:

Perfect

I don't know what it is; Correct me if I wrong, but I think we can replace it with NotImplementedError.

We need to remove [1, 2]. But do not add NotImplementedError. Sometimes we do not need initial_data. So some channel controller could not have any methods.

Also we need to check initail_data result in subscribe to not call Logux.add if nothing was added.

ai avatar Nov 28 '18 11:11 ai