-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add block #436
Comments
Thanks. I can reproduce it. |
Could you add the |
No, it does not use that class. the See here, it does not use that class. |
Why are we comparing on classes? I thought this is why we defined Can we not just remove this check on classes instead? I'm not sure why it's there. Wasn't the logic:
|
@JohnCoene the problem here is the following I believe: In order to check whether a new block can be inserted in a (tail) position we have to check whether the input type of the new block matches the output type of the previous. In order to do so, we have to be able to look up the registry entry of the previous block. And this is what I am attempting in #445, essentially by using a "registry ID" and saving that with the block. One issue wich such an approach (cc @DivadNojnarg) is that we introduce a dependency (for a serialized block) on the runtime (registry) state from when/where the block was created. This will cause issues if for example a block was added to the registry in one session, but is not available in the session where the block is being restored. |
Another issue: blocks that are not created in-app, but eg via set-up as new_stack(
new_dataset_block("iris")
) are missing the required "registry link" as well. In light of these issues, it might make more sense to store the block attributes we require over the entire block-lifetime directly with the block and set this up during object construction. We keep all registry-concerned metadata with the registry (such as name, description, category), but move input/output to the block definition. This will involve a breaking change to how blocks are defined. I see two ways of doing this:
As for the input/output specification, we could improve this as well. We could do something like
That way the "backend" just has to @DivadNojnarg any thoughts? I'm kind of leaning towards the generic approach as we're using this pattern in many places already and this seem to be the least "intrusive" change. |
Overall, I'd prefer if we could use generics to have more customisation options. Could we have a mix of 1 and 3 like: new_block <- function(fields, expr, name = rand_names(),
submit = FALSE, ...,
class = character()) {
stopifnot(
is.list(fields),
all(lgl_ply(fields, is_field)),
is.language(expr),
is_string(name)
)
if (is.na(submit)) {
submit <- 0
} else {
submit <- if (submit) 1 else -1
}
blk <- structure(fields,
name = name, expr = expr, result = NULL, submit = submit, ...,
class = c(class, "block")
)
attr(blk, "input") <- block_input(blk)
attr(blk, "output") <- block_output(blk)
blk
} |
Anywhere we need to. For example in for (x in get_registry()) {
identical(block_input(x()), block_output(stack[[length(stack)]]))
} to check which new blocks are compatible with the current last stack block.
Whenever a block constructor is defined. And yes that'd be a major breaking change. But the same holds true for option (1). That's why I am leaning towards (3). |
Ok, 3 seems fine to me, as we expose a better API around inputs/outputs. With such approach we also don't need all the work around block id, and we can probably drop the get_registry() function? |
We have an issue in the add block, where it does not the right blocks or does not show any block available when it should.
See {blockr.composer} register: https://github.com/BristolMyersSquibb/blockr.composer/blob/master/R/register.R
I would expect to be able to add a
new_freq_block
after anew_create_table_block
since theirinput
andoutput
match but when I have anew_create_table_block
I'm unable to add any block after it.The text was updated successfully, but these errors were encountered: