Feature: add ability to call custom transaction functions #16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/custom-transactions"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We'd like to be able to abstract away complex operations on transactions and still be able to chain them as part of a sequence of operations along with other simpler operations. Here's a simple example use case.
You could imagine the branching logic within the custom function being a lot more complex, and maybe you'd even want to be able to chain multiple of them together.
Since this is my first time contributing to prosemirror, I wasn't sure if we want features to have an associated ticket in the github issue tracker, or only bugs. If so, I'll create one and link it to this.
@ -44,0 +44,4 @@// :: ((Transaction, ...args: *)) → Transaction// Applies the given function to the transaction. The function must// take a [`Transaction`](#state.Transaction) as its first argument.chain(transactionFunction, ...args) {Not sure about this name. There's probably a better one🙂
@ -41,6 +41,14 @@ export class Transaction extends Transform {this.meta = Object.create(null)}// :: ((Transaction, ...args: *)) → TransactionWasn't sure if we needed to specify a return type of
*for the argument functionI don't think introducing a regular function call in a piece of code is a big enough problem to justify a feature like this. For things like conditionals and loops you'll already have to leave the method chaining format, you can make calls on a local variable for custom functions as well, I'd say.
I'm probably misunderstanding what you're saying, but conditionals and loops are just what this would allow us to abstract away so that we could continue chaining. For example, you could do
tr.chain(fn)wherefncontains any number of loops or conditionals that tack on modifications to the transaction.Nevermind, I think I understand what you're saying. You're referring to the conditional within
fn, which would not be chained, I guess. This newchainmethod is really just a way to abstract away this kind of complexity from the perspective of the caller, and so just to make sure I understand then, your opinion is that it's not worth adding this extra functionality to be able to create abstractions in these kinds of use cases?Right, you could pass conditional or looping functions to
chain, that's true. But I really don't think being able to chain everything is a very important thing for this interface to support, so no, I don't think this is worth adding.Pull request closed