Skip to content
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

Allow Kino.JS.Live outputs to be exported #321

Merged
merged 1 commit into from
Aug 28, 2023
Merged

Allow Kino.JS.Live outputs to be exported #321

merged 1 commit into from
Aug 28, 2023

Conversation

jonatanklosko
Copy link
Member

Also improves the export API for Kino.JS.

Comment on lines +331 to +335
## Options

* `:export` - a function called to export the given kino to Markdown.
This works the same as `Kino.JS.new/3`, except the function
receives `t:Kino.JS.Live.Context.t/0` as an argument
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim I made this an option instead of a callback, for two reasons:

  1. It better mirrors Kino.JS, so should be more intuitive. We also have the option on Kino.Table, this way they are all consistent.

  2. In some cases the original data may not be passed to the server directly (see Kino.DataTable.new/2). Passing it to the state for the purpose of export is not different from closure, but if it's large data then it may be better to just call inspect/1 right away and close over that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure if should actually be passing the state to that function. If we do that, then people may make the export reflect the state (e.g. page when paginating the table). It is undesired, because (a) we wouldn't know that we should re-save when the page changes, so it would end up pretty arbitrary (b) it wouldn't reflect the actual value, that is, if the cell returns df and we suddenly persist 10th page, it's weird. Thoughts?

IO.warn(
"passing :export_info_string to Kino.JS.new/3 is deprecated. Specify an :export function instead"
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we have to update many kinos or only Kino.VegaLite?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kino.Maplibre too!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other one I found is kino_wardely.

Copy link
Contributor

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! It is only a question if we want to deprecate it now or in a future release. If we deprecate it now, we will have to release new packages for Kino.VegaLite that depend on latest Kino immediately. If it is only Kino.VegaLite it is fine, but if there are more, maybe we want to wait.

@jonatanklosko
Copy link
Member Author

@josevalim I think it's fine, the new kino brings important changes like support for files and the changed output format, so pushing for newer version makes sense.

@jonatanklosko jonatanklosko merged commit 8688d80 into main Aug 28, 2023
1 check passed
@jonatanklosko jonatanklosko deleted the jk-export branch August 28, 2023 11:20
@hugobarauna
Copy link
Member

Did we update our Kinos according to this?

@jonatanklosko
Copy link
Member Author

Not yet. We need to update kino_vega_lite and kino_maplibre, but this will require bumping to kino ~> 0.11, so we are waiting. We may still want to update kino_explorer now that we can export Kino.JS.Live, @josevalim?

@jonatanklosko
Copy link
Member Author

Actually I will add a conditional to kino_vega_lite and kino_maplibre :)

"""
@spec new(module(), term(), keyword()) :: t()
def new(module, data, opts \\ []) do
# TODO: remove the old export options in Kino v0.14.0
export =
if info_string = opts[:export_info_string] do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opts[:export] || if ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants