console.log('>>> script ready');

ko.extenders.maxCharacters = function(target, max) {
    var result = ko.pureComputed({
        read: target,
        write: function(newValue) {
            var current = target();

            if (newValue.length <= max) {
                target(newValue);
            }
            target(current);
            target.notifySubscribers(current);
        }
    }).extend({
        notify: 'always'
    });
    return result;
};

var Example71ViewModel = function() {
    var self = this;

    self.maxCharacters = 10;

    self.myText = ko.observable('')
        .extend({
            maxCharacters: self.maxCharacters
        });

    self.charactersRemaining = ko.computed(function() {
        return self.maxCharacters - self.myText().length;
    });
};

var example71ViewModel = new Example71ViewModel();
ko.applyBindings(example71ViewModel);
