Browse Source

Platform API: fetch.

Herby Vojčík 5 years ago
parent
commit
d85350986a

+ 13 - 0
lang/API-CHANGES.txt

@@ -1,3 +1,16 @@
+0.23.2:
+
++ Platform class >>
+  + fetch:
+  + fetchUrl:options:
++ BrowserPlatform >>
+  + fetch:
+  + fetchUrl:options:
++ NodePlatform >>
+  + fetch:
+  + fetchUrl:options:
+
+
 0.23.1:
 
 + TBehaviorDefaults >>

+ 90 - 0
lang/src/Platform-Browser.js

@@ -12,6 +12,96 @@ $core.addClass("BrowserPlatform", $globals.Object, [], "Platform-Browser");
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.BrowserPlatform.comment="I am `Platform` service implementation for browser.";
 //>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "fetch:",
+protocol: "public API",
+fn: function (aStringOrObject){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $early={};
+try {
+$recv($self._globals())._at_ifPresent_ifAbsent_("fetch",(function(fetch){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+throw $early=[$recv(fetch)._value_(aStringOrObject)];
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({fetch:fetch},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),(function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._error_("fetch not available.");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+//>>excludeEnd("ctx");
+}));
+return self;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"fetch:",{aStringOrObject:aStringOrObject})});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aStringOrObject"],
+source: "fetch: aStringOrObject\x0a\x09self globals at: #fetch\x0a\x09\x09ifPresent: [ :fetch | ^ fetch value: aStringOrObject ]\x0a\x09\x09ifAbsent: [ self error: 'fetch not available.' ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["at:ifPresent:ifAbsent:", "globals", "value:", "error:"]
+}),
+$globals.BrowserPlatform);
+
+$core.addMethod(
+$core.method({
+selector: "fetchUrl:options:",
+protocol: "public API",
+fn: function (aString,anObject){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $early={};
+try {
+$recv($self._globals())._at_ifPresent_ifAbsent_("fetch",(function(fetch){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+throw $early=[$recv(fetch)._value_value_(aString,anObject)];
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({fetch:fetch},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),(function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._error_("fetch not available.");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+//>>excludeEnd("ctx");
+}));
+return self;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"fetchUrl:options:",{aString:aString,anObject:anObject})});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString", "anObject"],
+source: "fetchUrl: aString options: anObject\x0a\x09self globals at: #fetch\x0a\x09\x09ifPresent: [ :fetch | ^ fetch value: aString value: anObject ]\x0a\x09\x09ifAbsent: [ self error: 'fetch not available.' ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["at:ifPresent:ifAbsent:", "globals", "value:value:", "error:"]
+}),
+$globals.BrowserPlatform);
+
 $core.addMethod(
 $core.method({
 selector: "globals",

+ 12 - 0
lang/src/Platform-Browser.st

@@ -14,6 +14,18 @@ globals
 
 !BrowserPlatform methodsFor: 'public API'!
 
+fetch: aStringOrObject
+	self globals at: #fetch
+		ifPresent: [ :fetch | ^ fetch value: aStringOrObject ]
+		ifAbsent: [ self error: 'fetch not available.' ]
+!
+
+fetchUrl: aString options: anObject
+	self globals at: #fetch
+		ifPresent: [ :fetch | ^ fetch value: aString value: anObject ]
+		ifAbsent: [ self error: 'fetch not available.' ]
+!
+
 newXhr
 	XMLHttpRequest
 		ifNotNil: [ ^ NativeFunction constructorOf: XMLHttpRequest ]

+ 90 - 0
lang/src/Platform-Node.js

@@ -12,6 +12,96 @@ $core.addClass("NodePlatform", $globals.Object, [], "Platform-Node");
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.NodePlatform.comment="I am `Platform` service implementation for node-like environment.";
 //>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "fetch:",
+protocol: "public API",
+fn: function (aStringOrObject){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $early={};
+try {
+$recv($self._globals())._at_ifPresent_ifAbsent_("fetch",(function(fetch){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+throw $early=[$recv(fetch)._value_(aStringOrObject)];
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({fetch:fetch},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),(function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._error_("fetch not available.");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+//>>excludeEnd("ctx");
+}));
+return self;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"fetch:",{aStringOrObject:aStringOrObject})});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aStringOrObject"],
+source: "fetch: aStringOrObject\x0a\x09self globals at: #fetch\x0a\x09\x09ifPresent: [ :fetch | ^ fetch value: aStringOrObject ]\x0a\x09\x09ifAbsent: [ self error: 'fetch not available.' ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["at:ifPresent:ifAbsent:", "globals", "value:", "error:"]
+}),
+$globals.NodePlatform);
+
+$core.addMethod(
+$core.method({
+selector: "fetchUrl:options:",
+protocol: "public API",
+fn: function (aString,anObject){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $early={};
+try {
+$recv($self._globals())._at_ifPresent_ifAbsent_("fetch",(function(fetch){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+throw $early=[$recv(fetch)._value_value_(aString,anObject)];
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({fetch:fetch},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),(function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._error_("fetch not available.");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+//>>excludeEnd("ctx");
+}));
+return self;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"fetchUrl:options:",{aString:aString,anObject:anObject})});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString", "anObject"],
+source: "fetchUrl: aString options: anObject\x0a\x09self globals at: #fetch\x0a\x09\x09ifPresent: [ :fetch | ^ fetch value: aString value: anObject ]\x0a\x09\x09ifAbsent: [ self error: 'fetch not available.' ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["at:ifPresent:ifAbsent:", "globals", "value:value:", "error:"]
+}),
+$globals.NodePlatform);
+
 $core.addMethod(
 $core.method({
 selector: "globals",

+ 12 - 0
lang/src/Platform-Node.st

@@ -14,6 +14,18 @@ globals
 
 !NodePlatform methodsFor: 'public API'!
 
+fetch: aStringOrObject
+	self globals at: #fetch
+		ifPresent: [ :fetch | ^ fetch value: aStringOrObject ]
+		ifAbsent: [ self error: 'fetch not available.' ]
+!
+
+fetchUrl: aString options: anObject
+	self globals at: #fetch
+		ifPresent: [ :fetch | ^ fetch value: aString value: anObject ]
+		ifAbsent: [ self error: 'fetch not available.' ]
+!
+
 newXhr
 	XMLHttpRequest
 		ifNotNil: [ ^ XMLHttpRequest new ]

+ 48 - 0
lang/src/Platform-Services.js

@@ -1664,6 +1664,54 @@ $core.addClass("Platform", $globals.Service, [], "Platform-Services");
 $globals.Platform.comment="I am bridge to JS environment.\x0a\x0a## API\x0a\x0a    Platform globals. \x22JS global object\x22\x0a    Platform newXHR \x22new XMLHttpRequest() or its shim\x22";
 //>>excludeEnd("ide");
 
+$core.addMethod(
+$core.method({
+selector: "fetch:",
+protocol: "accessing",
+fn: function (aStringOrObject){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self._current())._fetch_(aStringOrObject);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"fetch:",{aStringOrObject:aStringOrObject})});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aStringOrObject"],
+source: "fetch: aStringOrObject\x0a\x09^ self current fetch: aStringOrObject",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["fetch:", "current"]
+}),
+$globals.Platform.a$cls);
+
+$core.addMethod(
+$core.method({
+selector: "fetchUrl:options:",
+protocol: "accessing",
+fn: function (aString,anObject){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self._current())._fetchUrl_options_(aString,anObject);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"fetchUrl:options:",{aString:aString,anObject:anObject})});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString", "anObject"],
+source: "fetchUrl: aString options: anObject\x0a\x09^ self current fetchUrl: aString options: anObject",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["fetchUrl:options:", "current"]
+}),
+$globals.Platform.a$cls);
+
 $core.addMethod(
 $core.method({
 selector: "globals",

+ 8 - 0
lang/src/Platform-Services.st

@@ -426,6 +426,14 @@ I am bridge to JS environment.
 
 !Platform class methodsFor: 'accessing'!
 
+fetch: aStringOrObject
+	^ self current fetch: aStringOrObject
+!
+
+fetchUrl: aString options: anObject
+	^ self current fetchUrl: aString options: anObject
+!
+
 globals
 	^ self current globals
 !