fastmail / Ix

automatic generation of JMAP-style APIs
GNU General Public License v2.0
10 stars 5 forks source link

Add context->scratchpad, for transient data #101

Closed mmcclimon closed 6 years ago

mmcclimon commented 6 years ago

This came up in Topicbox, where we needed to keep track of a bunch of updates during a single transaction, then do something at the end of it.

Each top-level transaction gets a new scratchpad, which is thrown away when that transaction finishes. This could maybe be an object, and have better namespacing, but this works for now.

mmcclimon commented 6 years ago

What would maybe make more sense is to say $context->scratchpad->for_call('setFoos'), which would give you a hashref that's unique for that call.

I considered that, but because of the way the hook system works, a single call stack inside Ix (ix_set) turns into potentially a bunch of different call stacks inside the client (ix_{creat,update,destroy}ed, plus ix_postprocess_{create,update,destroy}), so if the scratchpad just returns a nonce reference, you still need somewhere in the client to store it, and it can't just be a lexical.

(This explanation might not make any sense).

mmcclimon commented 6 years ago

Good call...both fixed now.

wolfsage commented 6 years ago

+1.

mmcclimon commented 6 years ago

We figured out a better way to do this in Topicbox, so I'm closing this now.