+///
+var Transformation = function(args) {
+ this.args = args;
+};
+$.extend(Transformation.prototype, {
+ run: function() {
+ throw new Error('not implemented');
+ },
+ undo: function() {
+ throw new Error('not implemented');
+ },
+});
+
+var createGenericTransformation = function(desc) {
+ var GenericTransformation = function(document, args) {
+ //document.getNodeByPath(contextPath).call(this, args);
+ this.args = args;
+ this.document = document;
+ };
+ $.extend(GenericTransformation.prototype, {
+ run: function() {
+ var changeRoot = desc.getChangeRoot ? desc.getChangeRoot.call(this) : this.document.root;
+ this.snapshot = changeRoot.clone();
+ this.changeRootPath = changeRoot.getPath();
+ return desc.impl.call(this.context, this.args); // a argumenty do metody?
+ },
+ undo: function() {
+ this.document.getNodeByPath(this.changeRootPath).replaceWith(this.snapshot);
+ },
+ });
+
+ return GenericTransformation;
+};
+
+// var T = createGenericTransformation({impl: function() {}});
+// var t = T(doc, {a:1,b:2,c3:3});
+
+
+var createContextTransformation = function(desc) {
+ // mozna sie pozbyc przez przeniesienie object/context na koniec argumentow konstruktora generic transformation
+ var GenericTransformation = createGenericTransformation(desc);
+
+ var ContextTransformation = function(document, object, args) {
+ var contextPath = object.getPath();
+
+ GenericTransformation.call(this, document, args);
+
+ Object.defineProperty(this, 'context', {
+ get: function() {
+ return document.getNodeByPath(contextPath);
+ }
+ });
+ }
+ ContextTransformation.prototype = Object.create(GenericTransformation.prototype);
+ return ContextTransformation;
+}
+// var T = createContextTransformation({impl: function() {}});
+// var t = T(doc, node, {a:1,b:2,c3:3});
+///
+
+var contextTransformations = {};
+contextTransformations['setText'] = createContextTransformation({
+ impl: function(args) {
+ this.setText(args.text);
+ },
+ getChangeRoot: function() {
+ return this.context;
+ }
+});
+
+contextTransformations['setAttr'] = createContextTransformation({
+ impl: function(args) {
+ this.setAttr(args.name, args.value);
+ },
+ getChangeRoot: function() {
+ return this.context;
+ }
+});
+
+contextTransformations['split'] = createContextTransformation({
+ impl: function(args) {
+ return this.split({offset: args.offset});
+ }//,
+ // getChangeRoot: function() {
+ // return this.context.parent().parent();
+ // }
+});
+
+// var TRANSFORMATION2 = function(f, getChangeRoot, undo) {
+// var context = this,
+
+
+// var transformation = createContextTransformation({
+// impl: f,
+// getChangeRoot: getChangeRoot,
+
+// });
+
+// var toret = function() {
+// var
+// f.apply(context, createArgs ? createArgs(arguments) : arguments)
+// };
+// return toret;
+// }
+