evhan55 / ploma

Ploma: High-fidelity ballpoint pen rendering for pressure sensitive tablets
http://plomaproject.tumblr.com
98 stars 11 forks source link

Get delta from array of strokes #7

Closed angelcabo closed 3 years ago

angelcabo commented 9 years ago

Hi there - I've been using ploma on a project I'm working on and so far so good!

In order to decide if I want to save updates made to a canvas back to my server I'd like to be able to check if the canvas has changes based on what I have already persisted. Unfortunately I can't just run a quick equality check on the array of strokes given the nature of the object. e.g. this will always eval as true.

var hasUpdates = alreadyPersistedStrokeData != ploma.getStrokes()

So, in my app I've made a simple helper using underscore to accomplish this:

_.filter(ploma.getStrokes(), function (obj) {
    return !_.findWhere(alreadyPersistedStrokeData, obj);
});

I was wondering if you think it makes sense to have this functionality as part of the core lib? Something like: this.deltaStrokes = function (compareStrokes) { ... };. Obviously if this was pulled in as core functionality you wouldn't want to add a dep on underscore, but I just wanted to get your thoughts on whether this made sense to include in ploma or not.

evhan55 commented 9 years ago

Hi @angelcabo ! Thank you for the note! It's great to hear the integration has been working so far.

Ah, array comparison is a problem in general in JavaScript, is that right? http://stackoverflow.com/questions/7837456/comparing-two-arrays-in-javascript

I think this is exactly why libraries like underscore, etc. exist.

I definitely don't want to include underscore or make it a dependency for Ploma. However, if you'd like to submit a PR with an implementation like the one in the above SO link, I would be happy to check it out, test it, and incorporate it!

Let me know what you think. Ev