Преглед изворни кода

more streaming API works

readstream ones are still lacking: next, peek, contents.
Postponing atm, will put at issue.
Herbert Vojčík пре 9 година
родитељ
комит
8f4602a068
2 измењених фајлова са 70 додато и 10 уклоњено
  1. 51 1
      src/DOMite.js
  2. 19 9
      src/DOMite.st

+ 51 - 1
src/DOMite.js

@@ -6,8 +6,58 @@ $core.packages["DOMite"].transport = {"type":"amd","amdNamespace":"domite"};
 
 $core.addClass('Domite', $globals.ProtoStream, ['element', 'reference'], 'DOMite');
 //>>excludeStart("ide", pragmas.excludeIdeData);
-$globals.Domite.comment="I am (hopefully thin) wrapper around the notion of \x22cursor in a page\x22.\x0aI represent a DOM node _and_ a point where\x0ato insert new content into it.\x0a\x0aSo I play both the role of a container that inserts\x0aas well as the role of an element being inserted.\x0a\x0aCreation API:\x0a\x0a - `Domite new` creates an insertion point at the bottom of `<body>`.\x0a - `Domite open` is unique way to create pieces of content. It creates an instance \x22floating in thin air\x22 (wrapper around DOM DocumentFragment) that can be filled with any contents and then inserted in a page.\x0a - `Domite fromElement: aDomElement` wraps an element and set the cursor to its end.\x0a\x0aManipulation API:\x0a\x0a - `aDomite insertDomite:` and `aDomite insertString:` insert either a Domite or a text content at the insertion point.\x0a - `aDomite clearHere` deletes contents of the wrapped element.\x0a\x0aCursor moving API:\x0a\x0aTake this sample HTML, where `[n]` are just markers, not real content:\x0a\x0a```\x0a<body>\x0a  <h1>header</h1>\x0a  [4]<p>[2]Hello[1]world[3]</p>[5]\x0a  <small>footer</small>\x0a</body>\x0a```\x0a\x0aIf `d` is a `Domite` representing `[1]`, then:\x0a\x0a - `d seekHereStart` would move `d` to be at `[2]`,\x0a - `d seekHereEnd` would move `d` to be at `[3]`,\x0a - `d seekBeforeHere` would move `d` to be at `[4]`, and\x0a - `d seekAfterHere` would move `d` to be at `[5]`.\x0a\x0aIt is not presumed one would use `seekXxx`\x0ato actually move around in a single instance.\x0aIt is envisioned this API will be used mostly\x0ain combination with `copy`, like\x0a`afterMe := self copy seekAfterHere`.";
+$globals.Domite.comment="I am (hopefully thin) wrapper around the notion of \x22cursor in a page\x22.\x0aI represent a DOM node _and_ a point where\x0ato insert new content into it.\x0a\x0aSo I play both the role of a container that inserts\x0aas well as the role of an element being inserted.\x0a\x0aI inherit from `ProtoStream`.\x0a\x0aCreation API:\x0a\x0a - `Domite new` creates an insertion point at the bottom of `<body>`.\x0a - `Domite newStream` is unique way to create pieces of content. It creates an instance \x22floating in thin air\x22 (wrapper around DOM DocumentFragment) that can be filled with any contents and then inserted in a page.\x0a - `Domite fromElement: aDomElement` wraps an element and set the cursor to its end.\x0a\x0aManipulation API:\x0a\x0a - `aDomite << obj` inserts obj at the insertion point.\x0a - `aDomite resetContents` deletes contents of the wrapped element.\x0a\x0aCursor moving API:\x0a\x0aTake this sample HTML, where `[n]` are just markers, not real content:\x0a\x0a```\x0a<body>\x0a  <h1>header</h1>\x0a  [4]<p>[2]Hello[1]world[3]</p>[5]\x0a  <small>footer</small>\x0a</body>\x0a```\x0a\x0aIf `d` is a `Domite` representing `[1]`, then:\x0a\x0a - `d setToStart` would move `d` to be at `[2]`,\x0a - `d setToEnd` would move `d` to be at `[3]`,\x0a - `d setToBefore` would move `d` to be at `[4]`, and\x0a - `d setToAfter` would move `d` to be at `[5]`.\x0a\x0aIt is not presumed one would use `setToXxx`\x0ato actually move around in a single instance.\x0aIt is envisioned this API will be used mostly\x0ain combination with `copy`, like\x0a`afterMe := self copy setToAfter`.";
 //>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "atEnd",
+protocol: 'testing',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=$recv(self._reference())._isNil();
+return $1;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"atEnd",{},$globals.Domite)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "atEnd\x0a\x09^ self reference isNil",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["isNil", "reference"]
+}),
+$globals.Domite);
+
+$core.addMethod(
+$core.method({
+selector: "atStart",
+protocol: 'testing',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=$recv(self._reference()).__eq($recv(self._element())._firstChild());
+return $1;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"atStart",{},$globals.Domite)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "atStart\x0a\x09^ self reference = self element firstChild",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["=", "reference", "firstChild", "element"]
+}),
+$globals.Domite);
+
 $core.addMethod(
 $core.method({
 selector: "attrAt:",

+ 19 - 9
src/DOMite.st

@@ -10,16 +10,18 @@ to insert new content into it.
 So I play both the role of a container that inserts
 as well as the role of an element being inserted.
 
+I inherit from `ProtoStream`.
+
 Creation API:
 
  - `Domite new` creates an insertion point at the bottom of `<body>`.
- - `Domite open` is unique way to create pieces of content. It creates an instance "floating in thin air" (wrapper around DOM DocumentFragment) that can be filled with any contents and then inserted in a page.
+ - `Domite newStream` is unique way to create pieces of content. It creates an instance "floating in thin air" (wrapper around DOM DocumentFragment) that can be filled with any contents and then inserted in a page.
  - `Domite fromElement: aDomElement` wraps an element and set the cursor to its end.
 
 Manipulation API:
 
- - `aDomite insertDomite:` and `aDomite insertString:` insert either a Domite or a text content at the insertion point.
- - `aDomite clearHere` deletes contents of the wrapped element.
+ - `aDomite << obj` inserts obj at the insertion point.
+ - `aDomite resetContents` deletes contents of the wrapped element.
 
 Cursor moving API:
 
@@ -35,16 +37,16 @@ Take this sample HTML, where `[n]` are just markers, not real content:
 
 If `d` is a `Domite` representing `[1]`, then:
 
- - `d seekHereStart` would move `d` to be at `[2]`,
- - `d seekHereEnd` would move `d` to be at `[3]`,
- - `d seekBeforeHere` would move `d` to be at `[4]`, and
- - `d seekAfterHere` would move `d` to be at `[5]`.
+ - `d setToStart` would move `d` to be at `[2]`,
+ - `d setToEnd` would move `d` to be at `[3]`,
+ - `d setToBefore` would move `d` to be at `[4]`, and
+ - `d setToAfter` would move `d` to be at `[5]`.
 
-It is not presumed one would use `seekXxx`
+It is not presumed one would use `setToXxx`
 to actually move around in a single instance.
 It is envisioned this API will be used mostly
 in combination with `copy`, like
-`afterMe := self copy seekAfterHere`.!
+`afterMe := self copy setToAfter`.!
 
 !Domite methodsFor: 'accessing'!
 
@@ -157,6 +159,14 @@ putOn: aStream
 
 !Domite methodsFor: 'testing'!
 
+atEnd
+	^ self reference isNil
+!
+
+atStart
+	^ self reference = self element firstChild
+!
+
 canSetToUpperLevel
 	^ self element parentNode notNil
 !