Why Never Change the Notifier in Receiving a Change Event

Why never change the notifier in receiving a change event

I think she means that if you don't really think about your code then you can introduce an infinite loop.

Most people when when they create the table would probably make columns 1, 2 editable and make column 3 uneditable since column 3 is just the difference between the two columns.

So when they write the TableModelListener they will check for the UPDATE event but forget to check to see which column is updated because they think the table won't allow them to update column 3.

They forget that when the TableModelListener updates column 3 another UPDATE event will be generated thus causing the infinite loop. Of course, proper coding, like in your example, will prevent the loop.

In general, it should not cause an exception.

The second point is about business rules. The business rules should be defined on one place, in this case the model. The data itself and the updating of the data should be done in a single place.

Flutter change notifier

The Issue

With ChangeNotifier you need to make sure you're referencing the same instance of the class that you're updating and listening to.

So Far So Good

You're creating an instance of the WebsocketsProvider class (which extends ChangeNofitier) in your MultiProvider widget and providing it as a ChangeNotifierProvider. Then, you're listening to that instance inside of your ClockSettingsPage. Everything is correct up to this point.

The Mismatch

Inside of your _TabsScreenPageState, you're creating a brand new instance of the WebsocketsProvider class and listening to that stream. This doesn't work because the ClockSettingsPage is listening to changes on a completely different instance of that class.

The Update

Override the initState method to your _TabsScreenPageState and call super like usual. Then, subscribe to the instance of the class created by Provider like this:

context.read<WebsocketsProvider>().subscribeToStream();

if the syntax above doesn't work you can do it the old-fashioned way:

Provider.of<WebsocketsProvider>(context, listen: false).subscribeToStream();

p.s. I didn't see you disposing of your streams anywhere. If you're not doing that please look into how to dispose streams in Dart. This will prevent memory leaks in your application.

Why does jQuery on change event fire multiple times?

The reason is because you are nesting your event handlers. You've placed a static event handler within a delegated one, so each time an event happens another handler is added. This is also the reason why nothing happens when you first select an option.

To fix the problem simply remove the inner static event handler:

$(document).on('change', '.gender-select', function() {
console.log($(this).find("option:selected").text());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<select class="gender-select">
<option value="">- Select Gender -</option>
<option value="m">Male</option>
<option value="f">Female</option>
</select>

Listening children's property change notifier using prototype's listeners property in Polymer not working

In devguide it writes:

When the property changes, the element fires a non-bubbling DOM event to indicate those changes to interested hosts.

https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#change-notification-protocol

It means that event listeners are invoked only on the x-child element, but not on its ancestors. This may be what you are missing.

jQuery .change() event is only fired once

You're not setting up the event handler properly:

$("select").change(retrieveProject);

In your code, you were calling the "retrieveProject" function, and the return value from that function call was being passed as the "change" handler (and of course having no effect). That's why it appeared that the event was being generated upon page load.

When you're working with a function as a value, you don't use () after the function reference — it's the reference itself (the function name, in this case) that you want. That's what needs to be passed to jQuery.

Also — and this is important — make sure that your code is run either in a "ready" or "load" handler, or else that your <script> comes after the <select> element on the page. If the script is in the document head, then it'll run before the DOM is parsed, and it'll have no effect. (Another way to deal with that would be to use an .on() delegated form as suggested in another answer.)


More: it looks like you're overwriting your <select> element when you fetch the content in "getProjects". Thus, you should definitely use the delegated form:

$(document).on("change", "select", retrieveProject);

Also, you should be using local variables in "getProjects":

function getProjects() {
var selectionList; // keep this local to the function - implicit globals are risky

$.getJSON("php/getProjects.php", function (data) {
selectionList = "<form><select>";
for (var i = 0; i < data.length; i++) {
selectionList += "<option name='prjTitle'>" + data[i].ProjectTitle + "</option>";
}
selectionList += "</select></form>";
}).complete(function() {
$('#project-selection-menu').append(selectionList).removeClass('hidden');
firstLoad = false;
});
}

UITextField text change event

From proper way to do uitextfield text change call back:

I catch the characters sent to a UITextField control something like this:

// Add a "textFieldDidChange" notification method to the text field control.

In Objective-C:

[textField addTarget:self 
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];

In Swift:

textField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)

Then in the textFieldDidChange method you can examine the contents of the textField, and reload your table view as needed.

You could use that and put calculateAndUpdateTextFields as your selector.

jQuery change event being called twice

All I can think of is that you used the same class on the form itself. if so, remove the myClass style from your form tag.

Corrected :
http://jsfiddle.net/rY6Gq/1/

Faulty one with double alert:
http://jsfiddle.net/rY6Gq/



Related Topics



Leave a reply



Submit