Does RXJS architecture allow implementation of a compatible Observable without including RXJS library? And if it does, is there any documentation/reference/examples for that?
I want to bring RXJS compatibility into some of my libraries, without bringing in the entire RXJS as a dependency. I have some custom events that I want to extend as Observable-compatible, so they can optionally work with a wide variety of RXJS versions, i.e. anywhere between v5 and v7+
This is a good question and I don't think there's any official documentation regarding this topic.
I guess you're refering to this proposal https://github.com/tc39/proposal-observable that should define some common groud for all Observable implementations. I've seen the TC39 proposal mentioned many times in RxJS issue tracker and commits aligning RxJS with the proposal. See this https://github.com/ReactiveX/rxjs/search?q=tc39&type=issues.
However, I've never seen anyone switching from one Observable implementation to another, though I believe it should be possible(?).
Related
On RxJS - Goals I read that their goal is better debuggability:
Goals
Provide more debuggable call stacks than preceding versions of RxJS
I have just started to use redux-observable which is quite easier for me to understand comparing it to redux-saga as I am already used to the reactive style with lodash and ramda (ok, fp style maybe ;). I was surprised that it's not possible to debug it yet. Is it true? If so, then I gotta switch to redux-sagas maybe or stick with redux-thunk.
Edit based on Jay Phelps's answer
By debugging I meant: "How to set a breakpoint on e.g. observable.map(...) in a browser?" With lodash I can set a breakpoint in the browser and it stops right there on the _.map(...). How to do it with redux-observable (or rxjs)? I don't want to depend on drawing of marble diagrams and console.log().
It certainly is possible to debug RxJS code. I think it's probably safe to say hardly anyone would use it if that wasn't the case--Angular2 is heavily built on it too.
The most common ways people use are the same ways they debug other JavaScript, breakpoints (e.g. debugger) and console.log()'s
There are more advanced techniques some users use like drawing dependency graphs or marble diagrams. André Staltz wrote about this recently, so that might be a helpful resource.
Ultimately, any kind of async programming is going to be harder to debug. This is not unique to redux-observable/RxJS; a quick search will reveal plenty of debugging concerns for redux-saga too.
It turns out that redux-thunk is the best solution for a vast majority of applications built because a majority of them do not have complex side effect concerns that justify something like redux-observable or redux-saga. Though if you are already proficient in RxJS, there's nothing wrong with using redux-observable.
redux-saga as a project has existed longer than redux-observable so that's certainly one major selling point. You'll find more documentation, examples, and likely are have a better community to get support from.
The counter being that the operators and APIs you learn in redux-saga aren't nearly as transferable as learning RxJS, which is used all over the place. redux-observable is super super super simple internally, it's really just giving you a natural way for you to use RxJS. So if you know RxJS (or want to), it's an extremely natural fit.
My advice at the moment for most people is that if you have to ask which one you should use, you probably should choose redux-saga.
(disclaimer: I am one of the maintainers of redux-observable and RxJS v5)
import Rx, { Observable } from 'rxjs'
const arrStream$ = Observable.of(1,2,3)
.do(x=>console.log('Before',x)) // 1, 2, 3
.map(x=>x*2)
.do(x=>console.log('After',x)) // 2, 4, 6
.subscribe(value=>doThingsWith(value))
// real console output
// Before 1
// After 2
// doThingsWith(2)
// Before 2
// After 4
// doThingsWith(4)
// Before 3
// After 6
// doThingsWith(6)
.do(debugValue=> console.log(debugValue))
I look that the signature of umbraco.content.AfterUpdateDocumentCache event uses umbraco.cms.businesslogic.web.Document object. Unfortunatelly it is deprecated in "Umbraco 7".
What is the new event?
I'm the same issue in umbraco.content.AfterClearDocumentCache event.
Thanks
It doesn't appear there's any analog for umbraco.content.AfterUpdateDocumentCache in the umbraco7 code.
It seems you may have to reconsider you implementation approach to the available events hanging off Umbraco.Core.Services.ContentService
Looking at the u7 implementation of ContentService.Publish, for example, this call the internal SaveAndPublishDo which shows that the PreviewXML and the ContentXML disc caches are called before firing the Saved and Published (via Umbraco.Core.Publishing.PublishingStrategy) events. I presume the old umbraco.content.AfterUpdateDocumentCache was a single event that happened after both of the aforemented events. In it's absence - i believe you may have to watch for the saved/published/deleted events separately.
I can see that there are a bunch of events that would cause the cache update and it'd be a pain to wire them up separately - but maybee a different approach specific to the granularity of the available events is an upgrade?!
It may also help to backtrack from Umbraco.Core.Cache.CacheRefresherBase where i see there are events like OnCacheUpdated. They exist end do fire - though i'm not sure if or where they are publicly exposed.
This is probably more appropriate as a comment (i need more pts) as it's not a 100% resolution to your question. Hopefully it may be helpful to nudge in the right direction?
http://issues.umbraco.org/issue/U4-3462
According to this thread, answered by members of the Umbraco team, the AfterUpdateDocumentCache should still be used and the deprecated parameters are safely ignorable
I decided to use AfterUpdateDocumentCache in Umbraco 7 but noticed two issues. First of these is double firing this event. Second problem is that I retrieve the same not modified content when rendering page just in this event.
Then I decided to use CacheRefresherBase and CacheUpdate event but still have the same problem. Probably due to additional cache refreshing propagation.
The only workaround I see is to use Thread.Sleep in the new Task and perform purging url a little bit later.
I am designing a package where I want to provide an API based on the observer pattern: that is, there are points where I'd like to emit a signal that will trigger zero or more interested parties. Those interested parties shouldn't necessarily need to know about each other.
I know I can implement an API like this from scratch (e.g. using a collection of channels or callback functions), but was wondering if there was a preferred way of structuring such APIs.
In many of the languages or frameworks I've played with, there has been standard ways to build these APIs so that they behave the way users expect: e.g. the g_signal_* functions for glib based applications, events and addEventListener() for JavaScript DOM apps, or multicast delegates for .NET.
Is there anything similar for Go? If not, is there some other way of structuring this type of API that is more idiomatic in Go?
I would say that a goroutine receiving from a channel is an analogue of an observer to a certain extent. An idiomatic way to expose events in Go would be thus IMHO to return channels from a package (function). Another observation is that callbacks are not used too often in Go programs. One of the reasons is also the existence of the powerful select statement.
As a final note: some people (me too) consider GoF patterns as Go antipatterns.
Go gives you a lot of tools for designing a signal api.
First you have to decide a few things:
Do you want a push or a pull model? eg. Does the publisher push events to the subscribers or do the subscribers pull events from the publisher?
If you want a push system then having the subscribers give the publisher a channel to send messages on would work really well. If you want a pull method then just a message box guarded with a mutex would work. Other than that without knowing more about your requirements it's hard to give much more detail.
I needed an "observer pattern" type thing in a couple of projects. Here's a reusable example from a recent project.
It's got a corresponding test that shows how to use it.
The basic theory is that an event emitter calls Submit with some piece of data whenever something interesting occurs. Any client that wants to be aware of that event will Register a channel it reads the event data off of. This channel you registered can be used in a select loop, or you can read it directly (or buffer and poll it).
When you're done, you Unregister.
It's not perfect for all cases (e.g. I may want a force-unregister type of event for slow observers), but it works where I use it.
I would say there is no standard way of doing this because channels are built into the language. There is no channel library with standard ways of doing things with channels, there are simply channels. Having channels as built in first class objects frees you from having to work with standard techniques and lets you solve problems in the simplest most natural way.
There is a basic Golang version of Node EventEmitter at https://github.com/chuckpreslar/emission
See http://itjumpstart.wordpress.com/2014/11/21/eventemitter-in-go/
I have a question about coroutine implementation.
I saw coroutine first on Lua and stackless-python. I could understand the concept of it, and how to use yield keyword, but I cannot figure out how it is implemented.
Can I get some explanation about them?
Coroutining is initiated by pushing the target address, then each coroutine switch exchanges the current PC with the top of the stack, which eventually has to get popped to terminate the coroutining.
See also: Implementing “Generator” support in a custom language. Generators are basically a limited form of (semi-)coroutines, most of what is discussed in that question applies here as well.
Also: How are exceptions implemented under the hood? While exceptions are obviously very different from coroutines, they both have something in common: both are advanced universal control flow constructs. (In fact, you can implement coroutines using exceptions and exceptions using coroutines.)
Microsoft introduced the IObservable<T> interface to the BCL with .NET Framework 4, and I thought, "Great, finally, I must use it!" So I dug deep and read posts and documentation and even implemented the pattern.
After doing so I've realized that the basic implementation actually sends all the T events to all of its subscribers without any filtering on it; i.e. plain broadcast. I read somewhere that the Observable pattern is meant for plain broadcast. I feel that this is not true and that I am missing something.
My questions:
If I add a filtering mechanism, what is the difference between using the Observable pattern and just using plain CLR events?
When should one use this pattern, and when should one choose to use plain CLR events?
What are the main advantages of the Observable pattern?
Observable is the cornerstone of the Rx library. They provide pretty much all the implementations and operators you'll need. The idea behind IObservable<T> and Rx is not just the "handling" of events, but enabling "LINQ to Events." So you can easily compose "event streams," which gives you a lot of power compared to regular event handling.
Note that the sample MSDN implementation of IObservable<T> is incorrect; the doc team has been notified.