Editor.isDirty() broken? - tinymce

The Editor.isDirty() does not seem to be working correctly. In our application we check the Editor.isDirty() flag. When it evaluates to true we need to move forward with some actions. If nothing has changed we don't want to waste processor time evaluating data that hasn't changed. In our case once the content is updated once isDirty() always evaluates to true. Even when nothing has changed.
The Editor.isDirty() function seems pretty simple:
isDirty : function() {
var self = this;
return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
}
The key seems to be the startContent property. That's what TinyMCE uses to determine a change has occured. Therefore I would expect this property to be updated when save() is called on the Editor. Looking through the code shows this does not happen. In fact startContent does is not reset anywhere which would support it's use here. Has anyone else seen this behavior, or am I using the Editor object incorrectly?
sidenote: TinyMCE version 3.5.7.

Related

Why does calling AutoFake.Provide() wipe out fakes already configured with A.CallTo()?

Why does calling fake.Provide<T>() wipe out fakes already configured with A.CallTo()? Is this a bug?
I'm trying to understand a problem I've run into with Autofac.Extras.FakeItEasy (aka AutoFake). I have a partial solution, but I don't understand why my original code doesn't work. The original code is complicated, so I've spent some time simplifying it for the purposes of this question.
Why does this test fail? (working DotNetFiddle)
public interface IStringService { string GetString(); }
public static void ACallTo_before_Provide()
{
using (var fake = new AutoFake())
{
A.CallTo(() => fake.Resolve<IStringService>().GetString())
.Returns("Test string");
fake.Provide(new StringBuilder());
var stringService = fake.Resolve<IStringService>();
string result = stringService.GetString();
// FAILS. The result should be "Test string",
// but instead it's an empty string.
Console.WriteLine($"ACallTo_before_Provide(): result = \"{result}\"");
}
}
If I swap the order of the calls to fake.Provide<T>() and A.CallTo(), it works:
public static void Provide_before_ACallTo()
{
// Same code as above, but with the calls to
// fake.Provide<T>() and A.CallTo() swapped
using (var fake = new AutoFake())
{
fake.Provide(new StringBuilder());
A.CallTo(() => fake.Resolve<IStringService>().GetString())
.Returns("Test string");
var stringService = fake.Resolve<IStringService>();
string result = stringService.GetString();
// SUCCESS. The result is "Test string" as expected
Console.WriteLine($"Provide_before_ACallTo(): result = \"{result}\"");
}
}
I know what is happening, sort of, but I'm not sure if it's intentional behavior or if it's a bug.
What is happening is, the call to fake.Provide<T>() is causing anything configured with A.CallTo() to be lost. As long as I always call A.CallTo() after fake.Provide<T>(), everything works fine.
But I don't understand why this should be.
I can't find anything in the documentation stating that A.CallTo() cannot be called before Provide<T>().
Likewise, I can't find anything suggesting Provide<T>() cannot be used with A.CallTo().
It seems the order in which you configure unrelated dependencies shouldn't matter.
Is this a bug? Or is this the expected behavior? If this is the expected behavior, can someone explain why it works like this?
It isn't that the Fake's configuration is being changed. In the first test, Resolve is returning different Fakes each time it's called. (Check them for reference equality; I did.)
Provide creates a new scope and pushes it on a stack. The topmost scope is used by Resolve when it finds an object to return. I think this is why you're getting different Fakes in ACallTo_before_Provide.
Is this a bug? Or is this the expected behavior? If this is the expected behavior, can someone explain why it works like this?
It's not clear to me. I'm not an Autofac user, and don't understand why an additional scope is introduced by Provide. The stacked scope behaviour was introduced in PR 18. Perhaps the author can explain why.
In the meantime, if possible, I'd Provide all you need to before Resolveing, if you can manage it.

How to moving fields in forms of ncurses

I've written a program in C using ncurses and specially forms. I need that a particular field of my form moves as I'm filling the form. I tried move_field, but it doesn't work.
Here is how I wrote it :
if (typact==ADSD && rowc>rowg )
{
move_field(field[ietg],rowg=rowc,colg);
refresh();
}
I'm sure that the move_field is executed (I use xCode for debugging my program). I presume that refresh is not sufficient. I tried also placing move_field between unpost_form and post_form like this:
if (typact==ADSD && rowc>rowg /* && !field_status(field[ietg]) */ )
{ unpost_form(my_form);
move_field(field[ietg],rowg=rowc,colg);
post_form(my_form); refresh();
}
but it doesn't work once again. The form is erased and re-posted without the texts I have written and the field is always in the same place.
How could I use move_field?
The manual page says
The function move_field moves the given field (which must be disconnected) to a specified location on the screen.
You can disconnect a field by retrieving the current list of fields with form_fields (and its length using field_count), removing the field from that list and updating the list using set_form_fields.
When using move_field, you must also (temporarily) unpost the form with unpost_form. Otherwise, move_field returns E_POSTED (The form is already posted). After moving the field, use post_form to get the form-driver to work with the updated form.
The test/move_field.c file in ncurses sources provides an example of these calls.

MongoDB check if a property exists (and a child property)

Is there a more conventional way to check if a property and a child property exists in a MongoDB document?
Right now I'm doing this to make sure it doesn't error when one of the properties or the whole document doesn't exist.
//Check to see if the document exists
if(Donate.findOne({'debit.id': debitID})) {
//Check to see if the document has the property "credit"
if(Donate.findOne({'debit.id': debitID}).credit){
//Check to see if the object credit has the property sent
if(!Donate.findOne({'debit.id': debitID}).credit.sent){
doSomething();
}
}
}
!Donate.findOne({'debit.id': debitID}).credit.sent is to see if sent is set to true. If it is I don't want to execute doSomething();
Try this:
Donate.findOne({'debit.id': debitId, 'credit.sent': {$exists: true}});
Although I'm not entirely sure what you're trying to do, as your code appears to be checking if the properties "credit" and "credit.sent" do not exist. If that's what you're looking for, then just change the $exists entry to false above.
EDIT : Realized the solution that #richsilv proposed is probably better depending on what you're trying to achieve. I'll let my answer if that's of any use to someone.
1) Using pure JS, not really. You could refactor your code to store Donate.findOne({'debit.id': debitID}) in a variable though. This would look like this :
var donation=Donate.findOne({'debit.id': debitID});
if(donation && donation.credit && donation.credit.sent){
doSomething();
}
It looks like you messed up with the ! operator : if you want to check for existence this is unneccessary, ! is used to check for inexistence.
2) You could use another language on top of JS that provides syntactic sugar.
Example using Coffeescript :
donation = Donate.findOne
'debit.id': debitID
if donation?.credit?.sent
doSomething()

Cookie return undefined in GWT

I have created cookie for user name. Its working fine.
But my problem is:
when i clear cookie and try Cookies.getCookie("uname"); then it will return undefined insted of null.
so how to deal with undefined value ?
I am trying that if uname is not set then goes to else part;
please help me.
Yes, it is like this. Failure by design, please see here
https://code.google.com/p/google-web-toolkit/issues/detail?id=2994
The recommended workaround works:
String val = Cookies.getCookie("uname");
if (val == null || "undefined".equals(val)) {
...
} else {
...
}
But normally it seems to work even without this workaround. In my case I got the 'undefined' on JavaScript level, but in Java code it was sufficient to check for null. The real problem which let crash the code was a few lines later and didn't have anything to do with the getCookie() method. So have a look if you really identified the line with the problem.

GWT EditorDriver Proxy Object Modification

This is an edited version of a question that I had previously asked (and that tbroyer answered) about why the isDirty() method didn't return true after attempting to modify the Editor version of an entity. I think that my understanding of the RequestFactory/EditorDriver handling of entities is the issue, and that the isDirty() question was a red herring. I've left my original question at the end of this question, but my new question is:
How can the entity (proxy) that is being edited by an EditorDriver be modified in code? Obviously values will be changed as a result of changes in the user interface; but I don't know how to change values 'behind the scenes'. My understanding is that the call to EditorDriver.edit() will create a copy of the proxy object, and that subsequently any changes to that copy will be applied to the original object using EditorDriver.flush(). But EditorDriver.edit() does not return a reference to the object that is being edited (unlike RequestContext.edit(), which does return a reference to the object being edited).
The original (ill-informed) question:
I don't understand why the EditorDriver.isDirty() method is not returning true in the following situation (the following onOrgSelectedEvent() method is invoked when a new Org has been selected from a listbox):
private IOrgProxy _org;
...
/**
* Loads the currently selected Org into the editor.
*/
#Override
public void onOrgSelectedEvent(final OrgSelectedEvent orgSelectedEvent) {
IOrgProxy org = _clientFactory.getCache().getOrgCache().getOrg(orgSelectedEvent.getOrgId());
_orgRequestContext = _clientFactory.getRequestFactory().newOrgRequestContext();
_org = _orgRequestContext.edit(org);
_orgEditorDriver.edit(_org, _orgRequestContext);
_org.setName(_org.getName() + " (edit)");
if (_orgEditorDriver.isDirty()) {
_org.setName(org.getName());
}
}
When I put breakpoints on the setName() calls I see that the first call changes the name in the editable Org object, but the second setName() call is never reached (i.e., _orgEditorDriver.isDirty() returns false).
Just as a side question, it seems strange to me that the EditorDriver.edit() method doesn't return the editable proxy object, and that I have to call RequestContext.edit(), but that's a very minor issue.
Why would isDirty be true just after edit? Clearly the user hasn't be given the time to do any change.
isDirty compares the current value of the subeditors to their original value, it doesn't care whether the object changed: if you lend the object to the editor, you implicitly gives it control over the edited object (for the edited properties).