Comments (19)
Please create a minimal example that only uses Om so we can minimize the variables. Thanks.
from om.
per request
(ns om-sandbox.test-list
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(defn rand-value []
(let [possible-values "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"]
(rand-nth possible-values)))
(defn gen-list [n]
(vec (repeatedly n rand-value)))
(defn test-list-item [item owner]
(om/component
(dom/li nil item)))
(defn test-list [items owner]
(reify
om/IWillMount
(will-mount [_]
(js/setInterval
#(om/transact! items [0] (constantly (rand-value)))
1000))
om/IRender
(render [_]
(dom/div nil
(dom/span nil (get items 0))
(dom/ul nil
(om/build-all test-list-item items))))))
(def items (gen-list 5))
(om/root items test-list (.getElementById js/document "content"))
from om.
The problem is that you want to build a component from a non-cursor value. This is no longer allowed and I've exposed knobs to make it possible to wrap simple values in cursors, 5498b64
from om.
A working version of your program based on master:
(deftype DefaultCursor [value state path]
om/ICursor
(-path [_] path)
om/IValueCursor
(-value [_] value))
(extend-type default
om/IToCursor
(-to-cursor
([n state] (DefaultCursor. n state []))
([n state path]
(DefaultCursor. n state path))))
(defn rand-value []
(let [possible-values "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"]
(rand-nth possible-values)))
(defn gen-list [n]
(vec (repeatedly n rand-value)))
(defn test-list-item [item owner opts]
(reify
om/IRender
(render [_]
(dom/li nil (om/value item)))))
(defn test-list [items owner]
(reify
om/IWillMount
(will-mount [_]
(js/setInterval
#(om/transact! items [0] (constantly (rand-value)))
1000))
om/IRender
(render [_]
(dom/div nil
(dom/span nil (om/value (get items 0)))
(dom/ul nil
(om/build-all test-list-item items))))))
(def items (gen-list 5))
(om/root items test-list (.getElementById js/document "app"))
from om.
On second thought I'm not really all that happy with my solution suggested above, as it then means you have to use om/value
everywhere. I see two options at the moment, automatically coerce, or supply two new explicit fns something like build-value
and build-values
. Better ideas welcome.
from om.
Maybe make build/build-all wrap the value in something atom'ish, basically a wrapper around the root state + a path. build may then derive child paths and transact! takes on swap! like semantics (aka no need to provide paths)
so (dom/span nil (om/value (get items 0)))
turns into (dom/span nil (get @items 0))
(om/swap! items update-in [0] (rand-value))
from om.
I have a real solution coming that leverages the new specify
feature.
from om.
fixed in master, bc81082
You just need to extend string to ICloneable
. Then we can make the JS value become a cursor via specify
.
(extend-type string
ICloneable
(-clone [n] (js/String. n)))
(defn rand-value []
(let [possible-values "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"]
(rand-nth possible-values)))
(defn gen-list [n]
(vec (repeatedly n rand-value)))
(defn test-list-item [item owner opts]
(reify
om/IRender
(render [_]
(dom/li nil item))))
(defn test-list [items owner]
(reify
om/IWillMount
(will-mount [_]
(js/setInterval
#(om/transact! items [0] (constantly (rand-value)))
1000))
om/IRender
(render [_]
(dom/div nil
(dom/span nil (get items 0))
(dom/ul nil
(om/build-all test-list-item items))))))
(def items (gen-list 5))
(om/root items test-list (.getElementById js/document "app"))
from om.
nice! thanks for the prompt response and a cool solution.
On Fri, Jan 3, 2014 at 5:58 AM, David Nolen [email protected]:
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/36
.
.......__o
.......<,
....( )/ ( )...
from om.
There is a problem in last example. If you update not only first item in items
, then calling of om/build-all
will not update <li>
's.
from om.
@aluuu can you give the full source that does not work for you. Thanks!
from om.
There it is. Only transact!
call changed.
(extend-type string
ICloneable
(-clone [n] (js/String. n)))
(defn rand-value []
(let [possible-values "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"]
(rand-nth possible-values)))
(defn gen-list [n]
(vec (repeatedly n rand-value)))
(defn test-list-item [item owner opts]
(reify
om/IRender
(render [_]
(dom/li nil item))))
(defn test-list [items owner]
(reify
om/IWillMount
(will-mount [_]
(js/setInterval
#(om/transact! items (constantly (gen-list 5)))
1000))
om/IRender
(render [_]
(dom/div nil
(dom/span nil (get items 0))
(dom/ul nil
(om/build-all test-list-item items))))))
(def items (gen-list 5))
(om/root items test-list (.getElementById js/document "app"))
from om.
Thanks looking into it.
from om.
This works fine for me using master. What version of Om are you using?
from om.
I'm in master too.
Just tried to execute git pull && lein install
in local om
repository and got the same.
In dependencies I have [om "0.1.4"]
. I'll try to investigate what's wrong and I'll tell you.
from om.
You need to run lein cljsbuild clean
if you switch Om versions.
from om.
Oh, wow. That works. Thanks!
from om.
And also one change. I updated my dependencies to get it work:
[org.clojure/clojurescript "0.0-2138" :scope "provided"]
[org.clojure/core.async "0.1.267.0-0d7780-alpha" :scope "provided"]
from om.
yes the README documents what your project.clj should look like.
from om.
Related Issues (20)
- Can't add custom children on remote ast
- Adding `index` as a parameter to `f` when using build-all HOT 1
- A component that implements IQuery needs data returned, otherwise even statically defined dom elements do not get rendered.
- [Wiki] Components, Identity, & normalization wiki link broken
- Bug on master: `mounted?` breaks in adv optimization
- No queries exist for component path HOT 4
- In reloadable workflow, "No queries exist for component path..."
- Specify :remote reads in transact! HOT 1
- Examples should use `defui`
- om.core and beta2 HOT 8
- Reconciler broken in ClojureScript 1.10.* HOT 6
- om.next Quickstart issues HOT 1
- Wiki Quick Start project.clj doesn't work with java 10 HOT 2
- [Wiki] Quick Start (om.next) - to see console logs Chrome users should enable Verbose output
- uri? already refers to: cljs.core/uri? being replaced by: cognitect.transit/uri? HOT 1
- Add support for componentDidCatch
- Arity exception when calling om.next/reader and om.next/writer with zero arguments in Clojure
- Advanced cljsbuild with default settings emits a warning
- Looks like the updates to GitHub have messed up the om.next docs HOT 1
- Readme Quick Start compilation fails @ bumping cljs version from 1.10.520 -> 1.10.597
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 om.