diff --git a/README.md b/README.md index d704d42..6a08d7c 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,7 @@ ExtendedDiff.types.delete('Text') The [source code](./diff.js#L1098) is a good example for this as the base `Diff(..)` is built using this API, but note that we are registering types on the `Types` object rather than on the `Diff` itself, there is no functional difference other than how the main code is structured internally. +*XXX handler context may change in the near future* The handler methods are all called in the context of the `Diff.types` object. To call a different type handler's methods use: diff --git a/diff.js b/diff.js index c98c205..e926ea6 100644 --- a/diff.js +++ b/diff.js @@ -1498,6 +1498,15 @@ Types.set('Text', { // stage to apply the results... // XXX add object compatibility checks... patch: function(obj, key, change){ + /* XXX this needs to be in the context of the diff/pathc instance... + var cache = this._text_cache = this._text_cache || {} + var lines = cache[obj] || obj.split(/\n/) + + var res = cache[obj] = this.typeCall(Array, 'patch', lines, key, change) + + // XXX do this on the finalize stage... + return res.join('\n') + //*/ return this.typeCall(Array, 'patch', obj.split(/\n/), key, change) .join('\n') }, @@ -1654,6 +1663,10 @@ var DiffClassPrototype = { }, } +// XXX need to make the diff object the universal context... +// ...currently the context for most things is .constructor.types +// which is global this anything that any handler does is not local +// to a particular diff instance... var DiffPrototype = { // system meta information... get format(){