## 2018-02-15 Polymorphic Identifiers?

```
element://body > #foo > #index2.md
```

- http get/put/options ?
-  inner html source?
- csv / array / content....

## Implementation Idea

- wrap `fetch` and implement GET / PUT / OPTIONS / DELETE for "element://#foo" and others
- fetch will result in a response... but the response can return a domain specific object as

JSON EXample:
```javascript
fetch("http://foo/bar.json").then(r => r.json())
```

DOM Example: that will return the reference to the real object
```javascript
fetch("element://#bar").then(r => r.object())
```

## Applications Ideas

- DOM elements
  - OPTIONS list structure
  - GET / PUT ... get set innerHTML / outerHTML
- Modules
  - OPTIONS parse modules to get inner structure
  - get deep links to methods
  - GET / PUT will update the module / (and runtime?)
- External Resources: TODO items, Trello, Email, Dropbox ... as in service workser


## Evaluation

- write other tools / browser for this API


## Contribution

- generic interface that could be better scripted (dataflow) 
- this way, the resources will provide a generically navigateable interface through "OPTIONS"
  - no need to study the REST request manual for find out how to get children of an element


## Future Work


- Syntax support for URLs  / Polymorphic identifiers in JavaScript

```
var methods = module://utils/MyClass/_methods // GET / PUT / OPTIONS? where does the verb go? @MarcelWeiher?

methods = [...] 

module://utils/MyClass/methodFoo = "methodFoo(a) => a * 2"

```

```javascript

var a = await query://body>div#hello

(await query://body>div#hello).foo()
```

How to parse polymorphic identifiers

### White space?

```javascript

var a = await query://body>div#hello ; var b = 3
(await query://body>div#hello ).foo()
```

### Nothing.... :-) 

```javascript
var a = await query://body>div#hello; var b = 3
(await query://body>div#hello).foo()
```

### Await implicit?

```javascript
var a = query://body>div#hello; var b = 3
(query://body>div#hello).foo()
```

### Syntax 

```javascript
// Problem... finding a syntax for internal polymorphic identifiers DSL

// With syntax:
var a = ~|http://foo/bar.html#bla|.foo

// Without syntax:
var a = (await fetch(`http://foo/bar.html#bla`).then(r => r.json())).foo

// With syntax:
~|http://foo/bar.html#bla| = {foo: "bar"} 

// Without syntax:
fetch(`http://foo/bar.html#bla`, {
  method: "PUT",
  body: {foo: "bar"}
})
```


### Use objects...


### As objects 

```javascript
new PoI(`http://foo/bar.html#bla`).get 
new PoI(`http://foo/bar.html#bla`).put = {foo: 3}
new PoI(`http://foo/bar.html#bla`).options
```

#### With functions

```javascript
PoI(`http://foo/bar.html#bla`).get() 
PoI(`http://foo/bar.html#bla`).put({foo: 3})
PoI(`http://foo/bar.html#bla`).options()
```

#### Properties

```javascript
PoI(`http://foo/bar.html#bla`).get 
PoI(`http://foo/bar.html#bla`).put = {foo: 3}
PoI(`http://foo/bar.html#bla`).options
```
```javascript
await PoI[`http://foo/bar.html#bla`]
PoI[`http://foo/bar.html#bla`] = {foo: 3}
PoI.options(`http://foo/bar.html#bla`) // problem...
```
=> can be implemented using proxies: no compiler adjustions

As function call
```javascript
await PoI(`http://foo/bar.html#bla`)
PoI(`http://foo/bar.html#bla`, {foo: 3})
```

Back to jQuery??
```javascript
await $(`#bla`)
$(`http://foo/bar.html#bla`, {foo: 3})
```




## Register Schemas

```javascript
fetch("livelyfile://body > div > #README.2md").then(r => r.text())

fetch("scheme:livelyfile", {
  method: "PUT", 
  body: {
    PUT: async function(request) {
      // request.body ???
      // expect return new Response()
    },
    GET: async function(request) {
    },
    OPTIONS: async function(request) {
      
    } // reflection API of our lively polymorphic identifiers
  }, // new Blob || "string" || {foo: } || new Object
}).then(r => r.text())

```

## Next Steps

- implement schemas for "query" and "querysAll"


