observer-pattern

How to combine two live data one after the other?

半腔热情 提交于 2019-12-04 18:38:00
问题 I have next use case: User comes to registration form, enters name, email and password and clicks on register button. After that system needs to check if email is taken or not and based on that show error message or create new user... I am trying to do that using Room, ViewModel and LiveData. This is some project that on which I try to learn these components and I do not have remote api, I will store everything in local database So I have these classes: RegisterActivity RegisterViewModel User

@Observes in sessionscoped bean?

社会主义新天地 提交于 2019-12-04 15:11:12
is following scenario possible? "SessionService" which is a stateless EJB fires an event "LoggedInEvent". A SessionScoped (Weld) bean "SessionBean" having a non static method observing the LoggedInEvent is called and initializes some things for that specific user. Is the correct instance of "SessionBean" called? Are all instances called? I can not find anything in the documentation. "The correct instance" is a slightly misleading wording. What happens is this: The SessionService is invoked (probably triggered by a web request). If it fires its LoggedInEvent , all registered observers are

Design pattern for implementing plugins in PHP applications

你离开我真会死。 提交于 2019-12-04 07:49:57
问题 Is there a consensus on how plugins should be implemented in a PHP application? I've looked into the observer pattern which comes close, it's really just a notification system and doesn't allow code to extend the application directly. I'm currently using a simple hook systems that I came up with: public function registerHook($hookName, array $params = array()) { $this->hooks[] = $hookName; foreach ( $this->plugins as $pluginName => $hooks ) { if ( in_array($hookName, $hooks) ) { $plugin = new

Rails 3: How to identify after_commit action in observers? (create/update/destroy)

佐手、 提交于 2019-12-04 07:31:40
问题 I have an observer and I register an after_commit callback. How can I tell whether it was fired after create or update? I can tell an item was destroyed by asking item.destroyed? but #new_record? doesn't work since the item was saved. I was going to solve it by adding after_create / after_update and do something like @action = :create inside and check the @action at after_commit , but it seems that the observer instance is a singleton and I might just override a value before it gets to the

How do I modify existing AS3 events so that I can pass data?

 ̄綄美尐妖づ 提交于 2019-12-04 04:33:51
So I want a way to set up events so that I can pass data without creating closures \ memory leaks. This is as far as I have got: package com.events { import flash.events.Event; public class CustomEvent extends Event { public static const REMOVED_FROM_STAGE:String = "removedFromStage"; public var data:*; public function CustomEvent(type:String, customData:*=null, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); this.data = customData; } public override function clone():Event { return new CustomEvent(type, data, bubbles, cancelable); } public override function

Consuming paginated service in Angular2 & Ionic2 using Observables

喜夏-厌秋 提交于 2019-12-03 21:57:53
I have a remote collection of interface Foo { id: string; properties: any; } Which I can access using a class FooAPIService { find(skip = 0): Promise<Foo[]> { // promises at most 5 Foos. to get more, use skip > 1 // pagination is server side } on(event: string, callback: (foo: Foo) => any) { // registers event handler, for events: created, updated, removed // events triggered when a change occurs server side } } As a newcomer to Angular2 (and Ionic2), I'm trying to figure out how to consume this according to best practices. I've been looking at examples of Observables, but I'm having trouble

browser instant updates with ajax/jquery

半城伤御伤魂 提交于 2019-12-03 20:30:46
I'm trying to reverse engineer how facebook handles their notifications, where when you get a message you get instantly notified via the browser. I've fiddled with it for a little bit and realized that there is always a pending GET request "listening" if you will to some sort of update from the server. This appears to be some sort of observer pattern. I was just wondering if this pattern was documented somewhere. Daniel Vassallo The technique is actually called Long Polling . This is one of the popular Comet techniques to get around the limitations of traditional polling. You may want to check

How can I Observe the contents of an 'a' tag - jquery

做~自己de王妃 提交于 2019-12-03 16:29:30
问题 I have a blank <a> tag that content is loaded into via an external piece of javascript. I want to observe the <a> and when its content changes perform another task. The content will only ever change once. Can this be done? I am using also using jQuery. Thanks in advance 回答1: You can use a mixture out of jQuery && DOM Level 3 events (see browser support below). If you want to check for any changes within the content , you could do this: var $a = $('a'); $a.one('DOMNodeInserted', function(e) {

Good way to have a Collection Listener?

一个人想着一个人 提交于 2019-12-03 15:12:03
问题 Is there a better way to have a listener on a java collection than wrap it in a class implementing the observer pattern ? 回答1: You should check out Glazed Lists It contains observable List classes, which fire events whenever elements are added, removed, replaced, etc 回答2: You can using the ForwardingSet, ForwardingList, etc., from Guava to decorate a particular instance with the desired behavior. Here's my own implementation that just uses plain JDK APIs: // create an abstract class that

How to combine two live data one after the other?

馋奶兔 提交于 2019-12-03 12:46:50
I have next use case: User comes to registration form, enters name, email and password and clicks on register button. After that system needs to check if email is taken or not and based on that show error message or create new user... I am trying to do that using Room, ViewModel and LiveData. This is some project that on which I try to learn these components and I do not have remote api, I will store everything in local database So I have these classes: RegisterActivity RegisterViewModel User UsersDAO UsersRepository UsersRegistrationService So the idea that I have is that there will be