observers

Rails 3: ActiveRecord observer: after_commit callback doesn't fire during tests, but after_save does fire

好久不见. 提交于 2019-12-07 15:24:28
问题 I have a Rails 3 application. I use after_save callbacks for some models and after_commit callbacks for one of the models. All of the code the code works fine, but during RSpec tests, the after_commit callback doesn't get called when I save a Thing model. e.g. class ThingObserver < ActiveRecord:Observer observe Thing def after_commit(thing) puts thing.inspect end end If I change the method name to after_save , it gets called fine during tests. I need to be able to use after_commit for this

How to share service data between components correctly in Angular 2

喜欢而已 提交于 2019-12-07 03:19:27
I want to create a service to get data from .json file once and share it to multiple subscribers. But now with my solution number of requests to get data from .json file equals to a number of a subscibers for my service. getconfig.service.ts import {Injectable} from 'angular2/core'; import {Http, Response} from "angular2/http"; @Injectable() export class ConfigService { config: any; http: Http; constructor(http: Http) { this.http = http; console.log('Inside service'); this.config = this.http.get('/config.json'); } } robotui.component.ts ... import {ConnectionService} from '../services

How to create Selector with parameters from string

安稳与你 提交于 2019-12-06 21:41:32
问题 I am writing a program using Swift 3.1 and Xcode 8.3.3. I want to create a class, responsible for moving entire view when keyboard appears and disappears. But I faced difficulties with creating custom Selector with parameters from string. To show or hide keyboard we need function: func keyboardWillShow(notification: Notification) { //Code moving view when keyboard appears } I am trying to create a selector like this: let selector = Selector(("keyboardWillShow") NotificationCenter.default

Polymer 1.x: Observers

一世执手 提交于 2019-12-06 16:15:22
问题 Ultimately, I want to select individual states from this geochart. But this question is limited to getting the observer labeled _computeData to fire in response to mutating the array of selected states. Reproduce the problem with the following steps: Open this jsBin. Clear the console. Select the state of Texas. Note the console reads: You selected: Colorado,South Dakota,Texas which is expected per this line: console.log('You selected: ' + this.selected); // Logs properly However, I expect

Rails 3: ActiveRecord observer: after_commit callback doesn't fire during tests, but after_save does fire

南楼画角 提交于 2019-12-05 23:44:30
I have a Rails 3 application. I use after_save callbacks for some models and after_commit callbacks for one of the models. All of the code the code works fine, but during RSpec tests, the after_commit callback doesn't get called when I save a Thing model. e.g. class ThingObserver < ActiveRecord:Observer observe Thing def after_commit(thing) puts thing.inspect end end If I change the method name to after_save , it gets called fine during tests. I need to be able to use after_commit for this particular model because in some situations the change to a "thing" happens in a web server, but the

How to detect switch between macOS default & dark mode using Swift 3

有些话、适合烂在心里 提交于 2019-12-05 07:54:49
I want to change my status bar app icon when the user switches from default to dark mode and vice versa (using Swift 3). Here’s what i have so far: func applicationDidFinishLaunching(_ aNotification: Notification) { DistributedNotificationCenter.default().addObserver(self, selector: #selector(darkModeChanged(sender:)), name: "AppleInterfaceThemeChangedNotification", object: nil) } ... func darkModeChanged(sender: NSNotification) { print("mode changed") } Unfortunately, it’s not working. What am I doing wrong? I'm using this Swift 3 syntax successfully: DistributedNotificationCenter.default

Using property observers on NSManaged vars

喜你入骨 提交于 2019-12-04 23:47:09
I have a var declared in a class like so: @NSManaged var isFavorite: Bool I would like to declare a property observer, very similar to the one below. var organization: String { didSet { postNotificationWithName( "newData" ) } } However, Swift tells me that having property observers on NSManaged vars is not allowed. Is there any way I can implement such a feature or something similar for my isFavorite variable? Tom Harrington Yes-- delete the @NSManaged . It's not absolutely required, but if you delete it you unfortunately need to implement get and set for the property. You would need to add

magento unable to load the observe class

和自甴很熟 提交于 2019-12-04 22:39:51
when i try to write the observer for the checkout_type_onepage_save_order event like following <events> <checkout_type_onepage_save_order> <observers> <Appeal_Consignor_Model_Observer> <type>singleton</type> <class>consignor/observer</class> <method>savedata</method> </Appeal_Consignor_Model_Observer> </observers> </checkout_type_onepage_save_order> </events> above code i tried in frontend as well as global . Even i tried following as well. <events> <checkout_type_onepage_save_order> <observers> <Appeal_Consignor_Model_Observer> <type>singleton</type> <class>Appeal_Consignor_Model_Observer<

Polymer 1.x: Observers

人盡茶涼 提交于 2019-12-04 22:00:44
Ultimately, I want to select individual states from this geochart . But this question is limited to getting the observer labeled _computeData to fire in response to mutating the array of selected states. Reproduce the problem with the following steps: Open this jsBin . Clear the console. Select the state of Texas. Note the console reads: You selected: Colorado,South Dakota,Texas which is expected per this line: console.log('You selected: ' + this.selected); // Logs properly However, I expect the console to also read: selected per this line: _computeData: function() { console.log('selected'); /

How can I trigger controllerless core Magento modules that watch <controller_action_predispatch> in <frontend> in config.xml from external script

若如初见. 提交于 2019-12-04 16:53:04
For background reference SEE: Magento: How do I get observers to work in an external script? I wanted to ask what the preferred method to 'replicate' a frontend controller's action from an external script is. I am creating an external SSO login for Magento EE 1.12. My code exists as the following in a php file. You can test it by creating test.php and replacing my user (185) with whatever your user ID is. Navigate to the page and then again. You will notice you are logged in and out, however in admin it will not show you as being online. Read on... <?php umask(0); require_once 'app/Mage.php';