Comments (5)
You can emulate context in a couple of ways:
- Pass it explicitly (e.g. as a first arguments to all components)
- Use global variable as a context (so intermediate parents don’t know
about what children use)
To watch for the changes, use rum/reactive
mixin and rum/cursor
to
create atom-like view of part of the tree. Here’s a great example:
https://github.com/tonsky/rum/blob/gh-pages/examples/examples.cljs#L272-L318
Does it answer your questions?
On Wed, Sep 2, 2015 at 4:37 PM Dmitry Manannikov [email protected]
wrote:
I have one single atom for state.
Some components may want to watch some parts of this atom.
But their parents pure components without data.For example: page header contain user control. Header doesnt have any data
from state, but user control have. In react I pass this state by context.
And wrap user control in container that watch data in state and pass as
props to user control. I can do it with rum, but I want to know is this
best way?Also my question not about only state atom, but about all things
components may want deep in tree.
In my case is state and dispatcher (chan).—
Reply to this email directly or view it on GitHub
#39.
from rum.
Almost.
Global vars is not an option.
It posible to write macro (or function?) that provide this variables to component?
Maybe it will use context #37
Because I wouldn't like to pass state across all components. Only component that interested in state receive it.
Root component (create state or receive from other code)
|
V
Statefull component (receive state from context?)
|
V
Stateless component (don't know about state)
|
V
Statefull component (receive state from context?)
In JS I can wrap component in decorator. Under the hood decorator create wrap component with another component. This wrapper get state (or api or another global var) from context and pass as property.
from rum.
Since this issue has been opened the ability to add context to a render tree has been added to Rum. @slonoed you can find an example for this here: https://github.com/tonsky/rum/blob/gh-pages/examples/rum/examples/context.cljs
I think this can be closed.
from rum.
@martinklepsch this way don't work with clojure data structures.
But anyway I found the way: keep state global, render rum in JVM (such cool) and rebind variables in threads.
from rum.
@slonoed right if your context is complex then this becomes an issue. You can put a function into context that will return the data you need, this way you're freed from Reacts context typing.
from rum.
Related Issues (20)
- rum 0.12.3 cannot be compiled in the project without ClojureScript HOT 6
- Document interop between React and Rum components
- Starting from 0.12.0: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. HOT 4
- textarea's not updating from a rum/react HOT 2
- Perceived performance regression between Rum 0.11.5 and 0.12.3 HOT 1
- rum/fragment with React components HOT 2
- optimizations :advanced (shadow-cljs) failing on simple :form :input
- defc error with shadow-cljs. Makes Rum unusable for me... :( HOT 22
- daiquiri: fragment? fails on vectors HOT 13
- Question about rendering performance when updating state asynchronously HOT 9
- should-update error
- Big performance regression between 0.11.5 and 0.12.3 HOT 9
- Server/client difference when rendering nil HOT 2
- require-lazy macro unnecessarily prescriptive about namespace/module structure HOT 1
- Error when use `rum/local` and `rum/use-callback` together HOT 2
- Hydration not fully compatible with React 18 HOT 4
- bind-context produces unfixable infer warnings HOT 3
- `with-key` and `with-ref` Removing children? HOT 2
- ClojureScript >=1.11.51 seems to break Rum HOT 4
- ClojureScript >=1.11.51 seems to break Rum 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 rum.