-
Notifications
You must be signed in to change notification settings - Fork 36
Add reactivity #25
Comments
I think weak references could help here - watcher' callback wouldn't capture direct reference to widget, and would just do nothing when it's null (possibly uninstall itself) |
Started experimenting here: BartAdv@8a6c5b0 |
Hello Bartosz, This certainly looks interesting. Possibilities for reactive programming were requested a couple of times from people trying Clojure/Android. I myself think this is a great way to go. Although I'm still not sure if Neko should enforce this kind of UI architecture. This approach needs evaluation to see if all the attributes can be described this way, will there be much performance overhead, can the ordinary traits and reactive traits coexist. I encourage you to continue your experiment and see what can come out of it. I'm leaving this issue open as work in progress. Thanks for your efforts and hope you enjoy CoA! |
Just to add my $.02: I've been working on a (by now) quite substantially-sized app, and had non-obvious references to UI components fall on my feet more than once. Besides, attaching UI elements directly to unfiltered application state only ever works at the beginning... until something flickers ... or gets to large for the widget size ... or is nil ... ;-) What seems to work well for now, is to keep state local, and publish updates via event buses (realized trivially with core.async and pubs), to which my activities or fragments subscribe in onResume, and from which they unsubscribe in onPause. The subscriptions themselves are kept in an atom that is local to the Activity/Fragment (following the same pattern as in for example Nightweb), so even if I forget to unsubscribe, all references to views that may be kept by the subscribers are going down with the containing object. |
@vschlecht Can you please take a look at the solution here #23 (last comment)? It is not reactive, but at least it is not locally-bound and should be much safer than keeping references in namespace vars. |
Honestly, I fail to see the point of using (*a) in this particular example: What I really like about (*a) is that it's quite an elegant solution to be used in REPL development that probably won't break things just by remaining in production code in the same way that :def a did. However I do not think that it should be used outside of the REPL for the following reasons:
IMHO by design, the use of (*a) will pollute every function that uses it with system-mutable global state. |
Actually, I pointed to the example that shows usage of I agree that As for the first point, to distinguish two activities in the same namespace (defactivity foo.bar.BazActivity
:key :baz
.....)
(*a :baz) => yields BazActivity instance |
As for the original point, I had experimented bit more back then, and it quickly became hairy as soon as I tried it to be bound two-way. It's pretty raw, uses quite low level primitives (watchers), and it tries to connect two distinct values: the original value, and the value kept by the widget, which does not map 1:1 (TextViews use entirely different structure than string for example). That's why it's just unfeasible to add such trivial reactivity on top of neko (which design goals are to sit on top of original SDK), and it would rather require something entirely different. As for the other point, I haven't yet given it a go. |
Hi,
So I've been experimenting with references and watches, and I came with idea of a trait that allows you to hook to the reference and alter the widget when reference value changes:
This helped me to refrain from fetching widgets by ids/vars and just allowed to focus on the values prepared for them:
There is one issue here: I haven't hooked to the widget destroy event to release the reference that watcher holds (I haven't yet found the way to do it, am not very knowledgeable in android SDK ;) ), but I'm pretty sure it can easily be done.
Real question is, do you think it would be feasible to alter existing traits to work this way if the value specified is a reference (just additional case)? Many traits would benefit from such thing, and it would give neko that 'reactive' feel (possibility of using dataflow programming a'la javelin for example, is so tempting). Or whether it's better as an 'add-on' (like I did in my code)?
The text was updated successfully, but these errors were encountered: