This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//.... | |
//.... | |
target.getChanges = function () { | |
var result = { | |
added: target.added(), | |
removed: target.removed() | |
}; | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ko.extenders.trackArrayChange = function (target, track) { | |
if (track) { | |
target.isDirty = ko.observable(false); | |
target.added = ko.observableArray([]); | |
target.removed = ko.observableArray([]); | |
var addItem = function (item) { | |
//... | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ItemA | |
{ | |
public string Identifier { get; set; } | |
} | |
public class ItemB | |
{ | |
public string Name { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EfficientIterator<TOne, TTwo> | |
{ | |
private Action<TOne, TTwo> always = (one, two) => { }; | |
private Action<TOne, TTwo> match = (one, two) => { }; | |
private Action<TOne> oneOnly = (one) => { }; | |
private Action<TTwo> twoOnly = (two) => { }; | |
private readonly Func<TOne, TTwo, int> compare; | |
public Action<TOne, TTwo> Always { set { this.always = value; } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<string> Validate(IDictionary<string, object> data, List<Field> mandatoryFields) | |
{ | |
var errors = new List<string>(); | |
foreach (var field in mandatoryFields) | |
{ | |
if (!data.Keys.Contains(field.Identifier)) | |
{ | |
errors.add(String.Format("The {0} field is required", field.Identifier); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var viewModel = { | |
Name: ko.observable("Pete"), | |
Age: ko.observable(29), | |
Skills: ko.observable({ | |
Tdd: ko.observable(true), | |
Knockout: ko.observable(true), | |
ChangeTracking: ko.observable(false), | |
Languages: ko.observable({ | |
Csharp: ko.observable(false), | |
Javascript: ko.observable(false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ((typeof obj == "object") && (obj !== null)) { | |
if (target.hasValueChanged()) { | |
return ko.mapping.toJS(obj); | |
} | |
return getChangesFromModel(obj); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ko.extenders.trackChange = function (target, track) { | |
if (track) { | |
// ... | |
// ... | |
if (!target.getChanges) { | |
target.getChanges = function (newObject) { | |
var obj = target(); | |
if ((typeof obj == "object") && (obj !== null)) { | |
if (target.hasValueChanged()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var viewModel = { | |
Name: ko.observable("Pete"), | |
Age: ko.observable(29), | |
Skills: { | |
Tdd: ko.observable(true), | |
Knockout: ko.observable(true), | |
ChangeTracking: ko.observable(false), | |
}, | |
Occupation: ko.observable("Developer") | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var traverseObservables = function (obj, action) { | |
ko.utils.arrayForEach(getObjProperties(obj), function (observable) { | |
if (observable && observable.value && !observable.value.nodeType && ko.isObservable(observable.value)) { | |
action(observable); | |
} | |
}); | |
}; | |
ko.extenders.trackChange = function (target, track) { | |
if (track) { |