Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the autoToggleCanExecute option #6

Closed
wants to merge 2 commits into from
Closed

Removed the autoToggleCanExecute option #6

wants to merge 2 commits into from

Conversation

patware
Copy link

@patware patware commented Oct 16, 2012

I removed the autoToggleCanExecute as requested.

Hi,

Presently, if the self.canExecute has a delegate, the delegate function
is called, else, the canExecute returns true.

I added an "autoToggleCanExecute" that when specified and true, would
toggle the boolean "canExecute" to false while the code is running.
This would prevent the user from "double clicking" for example.

For a reason I can't figure out, the "completeCallback" doesn't get
fired, so my tests are not conclusive.

Here's what I did for tests:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p>ping: <span data-bind="text:message">You need JavaScript turned
on.</span></p>
<p>Test sync command <button data-bind="command:testCommand">Test
Command</button></p>
<p>Test sync command <button data-bind="command:testAsyncCommand">Test
asyncCommand</button></p>
<p>Enable or Disable the button: <input type="checkbox"
data-bind="checked:canGo" /></p>

<script src="Scripts/jquery-1.8.2.js"></script>
<script src="Scripts/knockout-2.1.0.js"></script>
<script src="Scripts/knockout.asyncCommand.js"></script>

<script type="text/javascript">
$(function () {
var ViewModel = function () {
var self = this;

self.message = ko.observable('pong');
self.canGo = ko.observable(false);

self.testCommand = ko.command({
execute: function (callback) {

self.message('sync command running');

for (i = 0; i < 1000; i++) {
self.message('sync command running [' + i + ']');

now = new Date();
}

self.message('sync command finished');

},
autoToggleCanExecute: true,
canExecute: function (isExecuting) {
return !isExecuting && self.canGo();
}
});

self.testAsyncCommand = ko.asyncCommand({
execute: function (callback) {

self.message('async command running');

for (i = 0; i < 1000; i++) {
self.message('async command running [' + i + ']');

now = new Date();
}

self.message('async command finished');

},
autoToggleCanExecute: true,
canExecute: function (isExecuting) {
return !isExecuting && self.canGo();
}
});

}

ko.applyBindings(new ViewModel());

});
</script>
</body>
</html>
@hfjallemark
Copy link

Still something wrong with the encoding. And we already fixed the asyncCommand (the regular synchronous command does not have an isExecuting). Check it out in the trunk:-)

@patware
Copy link
Author

patware commented Oct 16, 2012

great.
I'm doing something wrong with github.
Pat

Date: Mon, 15 Oct 2012 19:47:38 -0700
From: notifications@github.com
To: KoLite@noreply.github.com
CC: patware@hotmail.com
Subject: Re: [KoLite] Removed the autoToggleCanExecute option (#6)

Still something wrong with the encoding. And we already fixed the asyncCommand (the regular synchronous command does not have an isExecuting). Check it out in the trunk:-)

          —

          Reply to this email directly or view it on GitHub.

@hfjallemark hfjallemark closed this Nov 5, 2012
@ghost ghost assigned hfjallemark Nov 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants