-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialize and sign operations, then enqueue them #100
Serialize and sign operations, then enqueue them #100
Conversation
I really like the idea of providing a way for |
I'm imagining an interface on CR itself for marshaling/serializing enqueued operations. Something like this perhaps. cable_ready[...]
.dispatch_event(...)
.outer_html(...)
.set_attribute(...)
.marshal(clear: true) |
Yeah the thing is I can’t expose that to a job I want the caller of the job to be able to provide a sequence of operations |
I've spent the last few hours working with this PR, in the context of the I want to get this out of the way: last night I was inspired by a conversation with @paramagicdev and built #108 without any notion that I was potentially reinventing something you'd been working on. Hopefully if you check out that PR, you'll see that I was working towards an entirely different end, which was to provide an agnostic interface with which devs could build CR client compatible JSON from enqueued operations. I figured that sooner than later, we'd need CR to work whether ActionCable was in the picture or not... hence, Now that I'm fully appraised of Julian's
The primary justification is that the syntax implied by #100 is effectively a "similar but different" syntax. The developer is building a hash instead of adding operations: after_save_commit CableReadyCallbacks::CableReadyMorph.new([{morph: {selector: "h3", html: "<h3>JUST GOT UPDATED</h3>"}}]) Instead, we can make it more like using the existing after_save_commit CableReadyCallbacks::CableReadyMorph.new cable_car.morph(selector: "h3", html: "<h3>JUST GOT UPDATED</h3>") I'd also love to see the addition of a convenience helper so that |
Enhancement
This PR allows the safe (de)serialization of operations to allow for the passing of such a
verified_operations
string to aCableReady::Channel
instance. This is useful especially for plugins depending on CableReady to allow for more flexibility.I've also added minimal YARD docs as a starter.
Rationale and Example
Working on https://github.com/julianrubisch/cable_ready_callbacks, I realized I needed to somehow pass operations as arguments to an ActiveJob, since (of course) serializing a block doesn't work.
So an exemplary use would look like this:
Implementation
This PR introduces a new convenience module to obtain an
ActiveSupport::MessageVerifier
(more or less copied from futurism) and aCableReady::OperationsSerializer
class to spit out the verified string.The meat is a new
apply
method inChannel
, essentially deserializing and enqueueing the operations passed to it.