Skip to content

Commit b0bf11b

Browse files
authored
Merge branch 'main' into main
2 parents 0484d0c + 64b567d commit b0bf11b

File tree

16 files changed

+166
-48
lines changed

16 files changed

+166
-48
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/ambv/black
3-
rev: 21.12b0
3+
rev: 22.1.0
44
hooks:
55
- id: black
66
- repo: https://github.com/PyCQA/flake8

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 Ryan S. Morshead
3+
Copyright (c) 2019-2022 Ryan S. Morshead
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.35.4
1+
0.36.0

docs/source/developing-idom/changelog.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ team are working on, or have feedback on how issues should be prioritized, feel
77
:discussion-type:`open up a discussion <question>`.
88

99

10+
0.36.0
11+
------
12+
13+
This release includes an important fix for errors produced after :pull:`623` was merged.
14+
In addition there is not a new ``http.script`` element which can behave similarly to a
15+
standard HTML ``<script>`` or, if no attributes are given, operate similarly to an
16+
effect. If no attributes are given, and when the script evaluates to a function, that
17+
function will be called the first time it is mounted and any time the content of the
18+
script is subsequently changed. If the function then returns another function, that
19+
returned function will be called when the script is removed from the view, or just
20+
before the content of the script changes.
21+
22+
**Closed Issues**
23+
24+
- State mismatch during component update - :issue:`629`
25+
- Implement a script tag - :issue:`544`
26+
27+
**Pull Requests**
28+
29+
- make scripts behave more like normal html script element - :pull:`632`
30+
- Fix state mismatch during component update - :pull:`631`
31+
- implement script element - :pull:`617`
32+
33+
1034
0.35.4
1135
------
1236

docs/source/reference-material/_examples/snake_game.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def on_direction_change(event):
8383
if snake[-1] in snake[:-1]:
8484
assign_grid_block_color(grid, snake[-1], "red")
8585
new_game_state = GameState.lost
86-
elif len(snake) == grid_size ** 2:
86+
elif len(snake) == grid_size**2:
8787
assign_grid_block_color(grid, snake[-1], "yellow")
8888
new_game_state = GameState.won
8989

src/client/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"publish": "npm --workspaces publish",
1515
"test": "npm --workspaces test"
1616
},
17-
"version": "0.35.4",
17+
"version": "0.36.0",
1818
"workspaces": [
1919
"./packages/*"
2020
]

src/client/packages/idom-app-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"format": "prettier --write ./src",
2222
"test": "echo 'no tests'"
2323
},
24-
"version": "0.35.4"
24+
"version": "0.36.0"
2525
}

src/client/packages/idom-client-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
"test": "uvu tests"
3232
},
3333
"type": "module",
34-
"version": "0.35.4"
34+
"version": "0.36.0"
3535
}

src/client/packages/idom-client-react/src/components.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function Element({ model }) {
3535
return null;
3636
}
3737
} else if (model.tagName == "script") {
38-
return html`<${ScriptElement} script=${model.children[0]} />`;
38+
return html`<${ScriptElement} model=${model} />`;
3939
} else if (model.importSource) {
4040
return html`<${ImportedElement} model=${model} />`;
4141
} else {
@@ -58,10 +58,31 @@ function StandardElement({ model }) {
5858
);
5959
}
6060

61-
function ScriptElement({ script }) {
62-
const el = React.useRef();
63-
React.useEffect(eval(script), [script]);
64-
return null;
61+
function ScriptElement({ model }) {
62+
const ref = React.useRef();
63+
React.useEffect(() => {
64+
if (model?.children?.length > 1) {
65+
console.error("Too many children for 'script' element.");
66+
}
67+
68+
let scriptContent = model?.children?.[0];
69+
70+
let scriptElement;
71+
if (model.attributes) {
72+
scriptElement = document.createElement("script");
73+
for (const [k, v] of Object.entries(model.attributes)) {
74+
scriptElement.setAttribute(k, v);
75+
}
76+
scriptElement.appendChild(document.createTextNode(scriptContent));
77+
ref.current.appendChild(scriptElement);
78+
} else {
79+
let scriptResult = eval(scriptContent);
80+
if (typeof scriptResult == "function") {
81+
return scriptResult();
82+
}
83+
}
84+
}, [model.key]);
85+
return html`<div ref=${ref} />`;
6586
}
6687

6788
function ImportedElement({ model }) {

0 commit comments

Comments
 (0)