RadLikeWhoa / Countable

Add live paragraph-, word- and character-counting to an HTML element.
https://sacha.me/Countable
MIT License
1.64k stars 134 forks source link

Issue with Knockout value driven area #35

Closed grofit closed 9 years ago

grofit commented 9 years ago

I was using once before every time an update happened which was fine, but I thought it would probably be easier to use live, but it doesnt update.

The element its targeting is driven by a knockout observable like so:

<div id="preview" data-bind="text: someTextObservable"></div>

So that div will change its content every time someTextObservable changes, now I notice in the source code that it is looking for key pressed based events, whereas in this case those would not apply as its a div not an input.

I know there are some events for mutations part of the newer html spec so not sure if you are fussed about supporting them or not, I can go back to just using once whenever it updates which is fine, but just wanted to raise this incase you wanted to extend support.

RadLikeWhoa commented 9 years ago

I'll have to look into this for a bit as I'm not too familiar with Knockout. I'll get back to you as soon as I can.

grofit commented 9 years ago

No rush, in this case it just provides observable objects so you can subscribe to them, like

var observableValue = ko.observable(20);
observableValue.subscribe(function(newValue) { stuffChanged(); });
observableValue(30); // this triggers stuffChanged
RadLikeWhoa commented 9 years ago

I'd love to get this to work, but I feel like it'd require quite a bit of code for a (probably) rather uncommon use case. I get why you'd want the functionality, but in the end, leaving the events delegated to Knockout and then doing the update separately using Countable should work best. I'll close this for now.

grofit commented 9 years ago

Thats cool, thanks for looking.