New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify angular demo #366
Conversation
@amark some quick questions:
I plan to drop gun-edge for now because I think it relies on old API (and also to workaround #322 as you noted in #365) and reimplement what I need from it in this demo, and maybe then make some PR to gun-edge or water-gun :) Thanks! edit: added a 4rd question :) |
- Use ngx-pipes to transform object to array of pairs - Extract GunDb in its own file - Introduce deletion
Use latest API and ensure unsubscription will be done.
c6fc02d
to
aa8771a
Compare
Oh, sorry for merging early! I was just excited to get angular in. :) Yeah, I'm most active on the gitter channel :) you should join it. I think we might be misunderstanding each others API familiarities? The api on gun is FRP on the items, maybe this is slightly off topic but hopefully it'll give you some context to then correct me in my misunderstanding: In gun While Further, because gun has a chaining API, you can combine
As a result, live updates to DOM elements is easy with gun's core FRP/observable API So I'm guessing similar for Angular, right? in the
So what am I missing? Please let me know! |
GenerallyI don't think you are missing anything, but I see things a bit different.
In the first case, you call the callback for each of the value to mutate the DOM, in the second case, you express the DOM as a function of the whole object. But that's not a problem with gun, since you can do On the questionsAbout 2., I meant cancelling an
But it didn't work (I got an exception, I don't have it next to me, but if it is the way it should be done, I will reproduce it). About 3, that's what I thought, but as explained above I am using gun.get('object').on(...) and the object I retrieve via the callback contains the key with a null value… is it expected of the user to check himself for the nullness of the value? Again I think some utility functions could be of help here maybe… |
Oh and I wanted to add: if you are advocating for a FRP experience, it could be interesting to have a full rxjs compliant wrapper for gun or even rewrite gun with rxjs directly ;) |
And question 5: is there any documentation on what exactly the callback of |
Add val$ and on$ to get observables (on$ can't be unsubscribed for now...)
Ah, yes, I see now, it is indeed easier to just give Angular the data and let IT handle the iteration. Stupid question though: Doesn't that require re-rendering the entire DOM list (versus just re-rendering the one item that changed?), which would be bad performance for large lists, and thus bad practice? To hand Angular the full object (I think you mentioned this already), do:
If you want to remove any
Or use any of your favorite (note, there are several extensions to gun like this that tweak gun's API to fit whatever exact need you want, that you can reuse, rather than having to use gun's universal API)
OffYes, this is what I meant by:
In the future The docs should be updated:
RxJSThere are some wrappers here: https://github.com/kristianmandrup/water-gun Rewriting gun to use RxJS would have some seriously damaging repercussions: gun's tens of millions of API ops/sec wouldn't be possible, and gun would have dependencies (currently gun has 0 dependencies, other than server-side plugins). Not that RxJS isn't great, it is, but there would be a severe performance penalty and dependency requirement. Did I answer everything? Let me know if I missed something. I especially think you'll find extensions to be very powerful and solve most of your itches. |
oh, and is this ready to pull yet? :D :D |
haha, let me get back to you on that, I need to process your answers (great by the way!). I will do that in the next few days :)
Yes, I guess (actually I'm not even sure, maybe it's even optimized not to recreate the list element themselves, which can be angular components for example, if the elements of the node do not change) it will need to rewrite the DOM for the loop on the node, not less, not more. Not our concern I think, at this scale this is nothing, angular handles that at best as it can. |
the Yeah. When I was working on the performance version of gun, I discovered all sorts of evil/terrible things about V8 and JS. Since then, I've lost any/all hope that it is possible for a framework to do this for you, because simple things like re-rendering the entire list for you (which is easy/nice) versus idempotently updating items, wind up being such different performance profiles (O(N) vs O(1)). Even supposed "magical" things like React's DOM diffing still have to do a lot of work (aka: performance loss) underneath to figure this out for you (somebody I know at a big SVG shop said React was too slow updating thousands of items in a dataviz). At this point, I'm starting to turn my eyes towards things like PixiJS and pure WebGL GPU shaders. A bit overkill, but I'm excited for the day when rendering a web page on modern hardware will be less intensive than running Crysis on my decade old desktop. :P |
Oh, and you might like this extension: https://github.com/IMGNRY/load (it recursively loads the full depth of any object you ask for, and then returns it to you once it is done. Having a live updating version of this might be nifty too) |
about performancesMaybe we are not talking about the same kind of use cases anyway :) I know also that you can implement some kind of interfaces on your iterable so that the angular loop does not repaint everything but detect where are the added or removed elements (https://angular.io/docs/js/latest/api/core/index/IterableDiffer-interface.html). about off()I understand that since you have chaining, you can't simply return an object via on() that corresonds to this current listener… or you could but you would need to change the API and Something like the option would work too, even if it's not the most elegant… With the current behaviour, it is impossible to About rxjsYes, I understand your arguments, again, I think it is about the use cases, and mine are maybe not the main ones of gun.js :) I checked the libraries, only water-gun is doing rxjs bindings, but it seems it is based on old APIs and does not take care of unsubscriptions (calling ConclusionTo complete this PR, I would prefer to have a complete rxjs wrapper, and for this, I would need a way to In the longer term, I would like to see if we can do something with |
For the record, Also filtering of the null values gives me this kind of error:
|
- gun 0.7.4 - angular 4.1.0 - typescript 2.3.2
Add an example of concurrent subscription to gun in the view with a button to subscribe and unsubscribe.
So I hacked sometimes for the unsubscription, so if you want you can merge. Are you using some kind of obfuscating tool before pushing code to github? The code in |
note also that the code in |
Sorry been gone the last week, my wife was graduating with her PhD. I'll check back in on this soon :). |
@amark no problem, congrats to her, big moment, I also had the pleasure of going through a PhD :) |
Sorry this took way too long! @victornoel what was your PhD in? Pulling finally! Thanks so much. :) |
thanks! It was on software engineering for self-organising and multi-agent systems :) |
@victornoel woah, that sounds incredible. Did you implement any prototypes? I'm definitely trying to build in that direction ;) would love your ideas/thoughts. |
The research team I was in did only that, building prototype and real applications of self-organising and emergent systems, mostly for problem solving, optimization and other kind of complex IA stuffs. If you are interested I also highly recommend reading about the AMAS approach promoted in my previous research team, it's not easy to understand at first, but it's impressive while you get the way of thinking of it :) Thank you for your interest, I rambled a lot there, I must miss this part of my professional life ^^ |
I particularly appreciated this page: http://ascens-ist.eu/casestudies/cloud.html which I got to through trying to find the "search and rescue" case study. A lot of the terms are way over my head :( but it looks super fascinating. What was the overall conclusion, that you drew personally, from it? Do you think they will work? Do you think most systems will have those sorts of things as their foundation? No no, I'm definitely curious. For instance, I gave this talk ( https://vimeo.com/208899228/b9bc9eaaa4 skip to 13:30 ) a few months ago, about how I think the future of programming will be based on emergent behavior from databases and codebases understanding their own Turing Complete structures. It is the future I'm wanting/trying to actively build. |
Sorry, took me some time to answer :) Basically, my personal conclusion is that these are hard questions and most people don't realise it, and don't have any good method/methodology to approach the design of self-organising systems (it's normal I have this opinion, since this was what my work was about ; ) Engineering this kind of system is complex, and that's why you need completely new design paradigms to approach them. You need to forget about the global functionality and look at local functions and how they could interact so that globally things still work (without trying to understand what's happening globally). I don't really think approaches were there is some kind of self-aware software, understanding its own functioning, and stuffs like that have a real future. If you look at a complex system working, after something happens, you can say "ah, it did this then that, because of that", but you couldn't have known before hand, and the system itself couldn't either. Emergence is exactly because the complexity resulting from the interactions is too much complex :) I haven't watched the video in details, but if I understood right, you talk about code self-elvolving because of their execution context, something like that, right? |
I wasn't really finished last time when you merged #365 :)
Let's keep this open until we finished discussing what can be improved!
This simplify some things:
ngx-pipes
to transform object to array of pairs (instead of my ugly code)GunDb
in its own file (just for clarity)It works well, but still, as I explained in my previous PR, the problem is that I think that gun wasn't meant to be really used like this…
From what I read in your examples and demos, when you want to iterate over the elements of the todo object, you use
gun.get('todos').map().on(...)
, i.e., you execute a function for EACH of the properties which will mutate the view.With angular and reactive programming, a common way of writing this would be more declarative: you specify how the view is expressed in function of the set of todos (see the html code). In my case, I use something that would end up calling
gun.get('todos').on(....)
(it isgun-edge
and its$rx
function that does this by making the new state of the object, i.e. the object passed to theon(...)
, into anObservable
event).And unfortunately, this object will contain not only the elements that would be present in the map, but also some special properties such as
_
which I then have to manually remove.So, I'm not sure how this kind of situation is meant to be handled with gun… and maybe gun should evolve w.r.t. to this kind of need? Or is there already some utility libraries that ease this kind of us?