Comments (11)
Yes, the LightTable/Reagent combo is a little tricky. Right now you should be able to change data dynamically, and have it update immediately in the browser.
But code is another matter. The problem is this: child components don't re-render unless their data (either an atom or their arguments) change β that's what makes Reagent fast. Unfortunately this also makes it awkward to force an update, which is what I think you'd want to do in LightTable.
So, what Reagent needs (I think) to work better with LightTable is a way to globally disable the caching. I'm not sure about the right api, though. Perhaps simply (reagent.core/always-update false)
or some-such?
Any thoughts?
Side note: In an ideal world, I'd like to be able to re-render everything automatically whenever you eval something in LightTable. But I don't think LightTable exposes the necessary hooks for that to be possible right now (but I haven't looked into this very deeply, so I might be completely wrong). It would be very cool, though.
from reagent.
A config-var like the one you suggest - for development purposes - would work just fine for me.
Right now I'm just really hooked on the whole live coding gimmick, so the sooner I can start living out this dream with Reagent, the sooner I'll start using Reagent for serious stuff! :-)
Anything I can do to assist - let me know.
from reagent.
Ok, I've been living the dream a little :)
I've added an experimental reagent.core/force-update-all
, that re-mounts and re-renders all root components. That can be used either by eval-ing it directly in LightTable, or by adding something like
"alt-r" [:eval-editor-form
(:eval.custom
"(if (exists? reagent.core/force-update-all)
(reagent.core/force-update-all)
\"Not available\")"
{:result-type :statusbar})]
to the :editor
section in user.keymap.
Then, alt-r will eval the current form, just like cmd-return, and reload all components at once. It seems to work fairly well, in my very hasty testing.
There is one gotcha, though. If do, say, (reagent/render-component [foo] (.-body js/document))
, and then later eval foo
, it will not be updated directly (you'll have to do the render-component again). That is because the function foo
is passed by value, so there's no way for Reagent to know that it has changed (that I can think of, at least).
foo
's children will be re-rendered though, so a solution for now is simply to pass a another component to render-component
, that returns [foo]
.
If you have an idea for a more elegant solution, let me know!
from reagent.
Great news! π
Seems like I haven't too much luck in using your new code though.. Perhaps I need more insight in Leiningen. I have a project with dependency reagent "0.4.3-SNAPSHOT". I've build 0.4.3-SNAPSHOT using lein cljsbuild once. Then I install it in my local m2 repo with lein install.
When I look in the .m2 repo for the local reagent-0.4.3-SNAPSHOT.jar, it contains the new version of core.cljs with force-update-all.
But my local project can't seem to find any reagent classes at all, until I revert my dependency to 0.4.2.
Any hints? :-)
from reagent.
I constantly feel I need more insight into Leiningen's mysteries as well :)
I can only say that it should work... When you do lein install
, you should get a directory in ~/.m2/repository/reagent/reagent, containing reagent-0.4.3-SNAPSHOT.jar. Then you should be able to use [reagent "0.4.3-SNAPSHOT"]
in :dependencies. At least that works for me :)
Btw, you can actually skip the "lein cljsbuild once" step.lein install
ought to be enough (it basically just packs all the sources into a jar, without touching anything compiled).
from reagent.
Alrighty ;)
I managed to get something to work with the supplied demo app. And when I press the suggested alt+r LightTable returns the "Updated" status. But the UI doesn't update anyhow.
I'll try to figure out why my leiningen won't use the local reagent-0.4.3-SNAPSHOT.jar.
Would you mind to email me the sample app you have where it works (luposlip at gmail dot com)?
Thanks again! :)
from reagent.
Ok, I think you're on your way :) If it says "Updated", that means that the new version has been picked up by LightTable at least.
I just pushed a commit where render-component
optionally takes a function returning a component, instead of the component directly, which should make LightTable happier. So, instead of (reagent/render-component [foo] (.-body js/document))
you can do (reagent/render-component (fn [] [foo]) (.-body js/document))
To see it in use you can check out the "simple" example, in the examples directory. It should work out of the box, after the usual lein install dance. Hopefully. :)
Just git pull, cd into examples/simple, and run make
. If you then open the "example/simple" directory as a workspace in LT, you ought to be able to just (a) open example.html, (b) hit cmd-return, and (c) change something and hit alt-r. Again, hopefully :)
from reagent.
Holy Moly - it works! :-D
Great stuff Dan, thanks a bunch!!
As of exactly right now, I'll start using Reagent for real stuff!
God aften i det Stockholmske!
from reagent.
Hey again - when do you plan to have an official release (0.4.3) containing this lighttable "hack"?
Best,
Henrik
from reagent.
Well, I plan to do a release a couple of weeks ago :) That plan obviously didn't work out, unfortunately, as plans tend to do.
I want to do some more testing before I release. Hopefully I can get some time to do that next week.
Thanks for reminding my already quite bad conscience...
from reagent.
Hi Dan,
Not to tickle your bad conscience any further, but I really need an official release with react 0.10.0 (and lighttable is a great add-on bonus). Any idea on when you'll get the time? :-)
Best regards,
Henrik
from reagent.
Related Issues (20)
- Infinite loop in the reagent.impl.input wrapper HOT 1
- Reaction value propagation glitch - the dirty flag is not set HOT 3
- Bad react key warning when using false as key
- examples/material-ui not work HOT 1
- examples/material-ui not work HOT 1
- Docs on βChanged?β inaccurate? HOT 5
- React 18 does not live reload with Shadow-CLJS in non-trivial projects HOT 5
- Prop types
- `TypeError` when using function components with `r/create-class` with `dom.server/render-to-string`
- ReactDOM.render is no longer supported in React 18. Use createRoot instead. HOT 2
- shadow-cljs emits a warning when using with-let HOT 4
- Korean input broken on :input and :textarea HOT 1
- Update docs? HOT 1
- MUI ThemeProvider not working HOT 1
- @@ -62,6 +62,45 @@ class _Config { } } // eslint-disable-next-line valid-jsdoc /** * fetch problem title, level via solved.ac api * @see {@link https://solvedac.github.io/unofficial-documentation/#/operations/getProblemByIdArray} * @param {string[]} pids - list of problem id (up to 100) * @param { ({ problemId, titleKo, level }) => void } callback */ function fetchProblemsFromSolvedAc(pids, callback) { const query = encodeURIComponent(pids.join(',')); console.log(`https://solved.ac/api/v3/problem/lookup?problemIds=${query}`); fetch(`https://solved.ac/api/v3/problem/lookup?problemIds=${query}`) .then((res) => { console.log('fetchProblemsFromSolvedAc', res); return res; }) .then((res) => res.json()) .then(callback) .catch(() => callback(null)); }
- Readme says npm i or add deps to .edn but (in my case at least) needed both HOT 1
- Any interest in being able to replace `react/createElement` with a custom function? HOT 7
- The cursor disappears at the end of a controlled input on Chrome
- Reusable components following HTML semantics of Opional Attributes and Variadic Children HOT 3
- Controlled input loses cursor under ShadowRoot in React 18 HOT 3
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 reagent.