Skip to content
This repository has been archived by the owner on Feb 23, 2019. It is now read-only.

Add Resource Module #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/Html.mint
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Html {
/*
Returns an empty Html node. It is useful for example if you dont to
Returns an empty Html node. It is useful for example if you dont want to

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Returns an empty Html node. It is useful for example if you dont want to
Returns an empty Html node. It is useful for example if you don't want to

render something conditionally.

if (Array.isEmpty(items)) {
Expand Down
8 changes: 4 additions & 4 deletions source/Http.mint
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ record Http.ErrorResponse {

/* Represents the possible failures of an HTTP request. */
enum Http.Error {
/* The request cannot be loaded because of a network faliure */
/* The request cannot be loaded because of a network failure */
NetworkError

/* The client (browser) aborted the request */
Expand Down Expand Up @@ -89,7 +89,7 @@ module Http {
}

/*
Creates a request record where the method is DELETE
Creates a request record where the method is GET

request =
Http.get("https://httpbin.org/get")
Expand All @@ -103,7 +103,7 @@ module Http {
}

/*
Creates a request record where the method is DELETE
Creates a request record where the method is PUT

request =
Http.put("https://httpbin.org/put")
Expand All @@ -117,7 +117,7 @@ module Http {
}

/*
Creates a request record where the method is DELETE
Creates a request record where the method is POST

request =
Http.post("https://httpbin.org/post")
Expand Down
4 changes: 2 additions & 2 deletions source/Map.mint
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Map {
}

/*
Sets the given value to the kiven key in the map.
Sets the given value to the given key in the map.

Map.empty()
|> Map.set("key", "value")
Expand Down Expand Up @@ -47,7 +47,7 @@ module Map {
}

/*
Merges two maps together where the second has the precendence.
Merges two maps together where the second has the precedence.

a =
Map.empty()
Expand Down
86 changes: 86 additions & 0 deletions source/Resource.mint
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* Functions for prebrowsing and resource hints. */
module Resource {
/*
Pre-loads a given URL with a type of resource as soon as possible.

Resource.preLoad("https://example.com/fonts/font.woff", "font")

Resource Types: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content#What_types_of_content_can_be_preloaded
*/
fun preLoad (url : String, type : String) : Promise(Never, Void) {
`
(() => {
var preLoadLink = document.createElement("link");
preLoadLink.href = url;
preLoadLink.rel = "preload";
preLoadLink.as = type;
document.head.appendChild(preLoadLink);
})()
`
}

/*
Pre-fetches a given URL with a low priority.

Resource.preFetch("page-2.html")
*/
fun preFetch (url : String) : Promise(Never, Void) {
`
(() => {
var preFetchLink = document.createElement("link");
preFetchLink.href = url;
preFetchLink.rel = "prefetch";
document.head.appendChild(preFetchLink);
})()
`
}

/*
Pre-fetches DNS of a given URL in the background.

Resource.preFetchDns("page-2.html")
*/
fun preFetchDns (url : String) : Promise(Never, Void) {
`
(() => {
var preFetchDnsLink = document.createElement("link");
preFetchDnsLink.href = url;
preFetchDnsLink.rel = "dns-prefetch";
document.head.appendChild(preFetchDnsLink);
})()
`
}

/*
preRender tells the browser to download the entire page in the background.

Resource.preRender("http://example.com/services.html")
*/
fun preRender (url : String) : Promise(Never, Void) {
`
(() => {
var preRenderLink = document.createElement("link");
preRenderLink.href = url;
preRenderLink.rel = "prerender";
document.head.appendChild(preRenderLink);
})()
`
}

/*
Establish a connection with given URL removing DNS lookup,
TCP handshake, and TLS negotiation round-trip for HTTPS.

Resource.preConnect("https://cdn.domain.com")
*/
fun preConnect (url : String) : Promise(Never, Void) {
`
(() => {
var preConnectLink = document.createElement("link");
preConnectLink.href = url;
preConnectLink.rel = "preconnect";
document.head.appendChild(preConnectLink);
})()
`
}
}