Commit 71d98d91 authored by David Davó's avatar David Davó

Misunderstood the schema

parent 339473ea
......@@ -26,4 +26,5 @@ stack.yaml.lock
result
default.nix
dist-*/
cabal.project.local
\ No newline at end of file
cabal.project.local
cabal.config
\ No newline at end of file
......@@ -39,9 +39,12 @@ the kernel.
## Displaying widgets
The creation of a widget does not display it. To display a widget, the kernel sends a display
message to the frontend on the widget's iopub, with a custom mimetype instead of text/plain.
You can also send the ViewModuleVersion in the two fields `version_major` and `verison_minor`.
Only the `model_id` is required.
message to the frontend on the widget's iopub, with a custom mimetype instead of text/plain. Since 5.0, all custom json metadata should be encoded as a json object, instead of as a serialized string.
The `version_major` and `version_minor` fields are the version number of the schema of this specific message
(currently in sync with the WMP version). However, only the `model_id` field is required to display the widget.
[Source](https://github.com/jupyter-widgets/ipywidgets/issues/3220)
```json
method = "display_data",
......
......@@ -110,7 +110,7 @@ library
-- The singletons package version is locked to the compiler
-- so let cabal choose the right one.
, singletons -any
, singletons < 3.0.0
-- Directories containing source files.
hs-source-dirs: src
......
......@@ -918,16 +918,13 @@ triggerDisplay = triggerEvent DisplayHandler
-- | Every IHaskellWidget widget has the same IHaskellDisplay instance, for this
-- reason we need to use FlexibleContexts. The display implementation can still
-- be overriden per widget
instance ('S.ViewModuleVersion WidgetFields w, IHaskellWidget (IPythonWidget w)) => IHaskellDisplay (IPythonWidget w) where
instance IHaskellWidget (IPythonWidget w) => IHaskellDisplay (IPythonWidget w) where
display b = do
widgetSendView b -- Keeping compatibility with classic notebook
(version_major,version_minor) <- versionToInteger <$> getField b ViewModuleVersion
return $ Display [ widgetdisplay $ unpack $ decodeUtf8 $ encode $ object [
"model_id" .= getCommUUID b,
"version_major" .= version_major,
"version_major" .= version_major,
"version_minor" .= version_minor] ]
where
versionToInteger :: Text -> (Int,Int)
versionToInteger str = toTuple (fmap (val.decimal) (splitOn "." str))
toTuple (x:y:_) = (x,y)
val (Right (v,_)) = v
version_major = 2 :: Int
version_minor = 0 :: Int
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment