Comments (11)
Hi @davydog187! This is an Elixir behaviour, you can't access variables from "outside" inside functions. But you should be able to pass them inside by using a module attribute:
ExUnit.start()
defmodule SportFeed.Test do
use ExUnit.Case
@feed Kino.Input.textarea("feed")
setup do
%{data: Kino.Input.read(@feed)}
end
test "it works", %{data: data} do
end
end
ExUnit.run()
You can also read the data before you store it.
from kino.
Thanks @josevalim. That was an approach I had tried, but you will get the following error
** (ArgumentError) cannot inject attribute @feed into function/macro because cannot escape #Reference<0.2064788886.4111204353.192084>. The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, PIDs and remote functions in the format &Mod.fun/arity
(elixir 1.13.0) lib/kernel.ex:3509: Kernel.do_at/5
(elixir 1.13.0) expanding macro: Kernel.@/1
feed_parser.livemd#cell:9: SportFeed.Test.__ex_unit_setup_0/1
from kino.
@josevalim we could make the input reference a string, we already do that for the JS widgets, so it would be consistent (it's more of an id, but we use the word id for reevaluation safe id 🙈). WDYT?
from kino.
If that's a reasonable solution I can send a PR
from kino.
Sounds good to me! @jonatanklosko, how you want to generate the binary references?
from kino.
I'd go with the same way we generate ids in Livebook, which is:
:crypto.strong_rand_bytes(20) |> Base.encode32(case: :lower)
I'll send a PR shortly, since there is probably a number of typespecs/docs to adjust too.
from kino.
@davydog187 for the record here's a working example https://gist.github.com/jonatanklosko/2ce5865e361ff1a70e43b3dcc686c1fa :)
from kino.
great, thank you @jonatanklosko!
from kino.
Reading this over again (thank you a ton for doing this!)
I realized that @davydog187 and @jonatanklosko use a different methods for accessing the value from kino.
Dave put the Kino input in the module attribute.
defmodule SportFeed.Test do
@feed Kino.Input.textarea("feed")
end
And Jonatan read the input in the module attribute.
feed = Kino.Input.textarea("feed")
defmodule SportFeed.Test do
@feed Kino.Input.read(feed)
end
Wanted to clarify in case anyone tries to use the first option and it doesn't work.
I'm not sure if the second option did or did not work originally, but regardless thank you all!
from kino.
@BrooklinJazz actually it's more like
# Cell 1
feed = Kino.Input.textarea("feed")
# [ Feed input ]
# Cell 2
defmodule SportFeed.Test do
@feed feed
# Then Kino.Input.read(feed) in tests
end
The point is that we need to render the input. We could also do @feed Kino.Input.textarea("feed") |> Kino.render()
, but that's less obvious.
In practice reading the value as you mentioned totally does the job, because re-running the tests involves redefining the module anyway :)
from kino.
@jonatanklosko Woah! @feed Kino.Input.textarea("feed") |> Kino.render()
totally works. That's really cool. This also helps me render multiple inputs so that's awesome.
Huge thank you 🙏
from kino.
Related Issues (20)
- Remote cell - allow cookie as a secret
- Kino.Input.utc_datetime uses DateTime.compare to compare NaiveDateTime values
- Support runtime temporary directory
- Kino.Input.text slow to render new input HOT 7
- Kino.Input.range doesn't work on Safari HOT 1
- Kino 11 giving error: Unknown output format HOT 2
- Improvements to remote execution cell HOT 5
- Changing sort column stays on the same page HOT 3
- Race condition when delaying Kino.JS.Live.call reply HOT 3
- Bug happening when running remote execution smart cell
- Add callback to `Kino.interrupt!` HOT 5
- Postgre columns of type array can crash SQL smart cells.
- Support `:list` in Kino Table
- Feature request: Multi-select HOT 2
- Refactoring DataTable assets
- Allow Kino.DataTable to be updated
- Rerender an input will make it losing focus HOT 1
- Expand tuples in Kino.Tree by default HOT 7
- Update to Glide Data Grid v6
- Reevaluating a cell containing Kino.start_child! sometimes errors with "Already started" HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kino.