-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support a single input element. (#58)
- Loading branch information
1 parent
07006b0
commit 03a8e70
Showing
9 changed files
with
305 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var aquascape = (function () { | ||
|
||
/** Draws an aquascape svg in-browser. | ||
* | ||
* @param exampleObject An instance of `aquascape.examples.Example`. | ||
* @param codeId The html id of the <code> element that should be populated. | ||
* @param frameIds An instance of `aquascape.examples.FrameIds` | ||
*/ | ||
function example(exampleObject, codeId, frameIds) { | ||
highlightExampleCode(codeId); | ||
exampleObject.draw(codeId, frameIds); | ||
}; | ||
|
||
/** Draws an aquascape svg in-browser with a single user input. | ||
* | ||
* The user-input is provided through an <input> element. | ||
* | ||
* @param exampleObject An instance of `aquascape.examples.Example`. | ||
* @param codeId The html id of the <code> element that should be populated. | ||
* @param frameIds An instance of `aquascape.examples.FrameIds` | ||
* @param labelId The html id of the <label> element for the input. | ||
* @param inputId The html id of the <input> element. | ||
*/ | ||
function exampleWithInput(exampleObject, codeId, frameIds, labelId, inputId) { | ||
highlightExampleCode(codeId); | ||
document.getElementById(inputId).addEventListener("input", function (e) { | ||
exampleObject.draw(codeId, frameIds, this.value); | ||
}); | ||
exampleObject.setup(labelId, inputId, codeId, frameIds); | ||
}; | ||
|
||
/** Highlight Scala code examples. | ||
* | ||
* The @:example directive fills in <code> blocks | ||
* asynchronously. This function adds an observer to highlight the | ||
* <code> block after its text content has been set. | ||
*/ | ||
function highlightExampleCode(codeId) { | ||
const targetNode = document.getElementById(codeId); | ||
const config = { attributes: true, childList: true, subtree: false }; | ||
|
||
const callback = (mutationList, observer) => { | ||
hljs.highlightElement(targetNode); | ||
observer.disconnect(); | ||
}; | ||
|
||
const observer = new MutationObserver(callback); | ||
observer.observe(targetNode, config); | ||
}; | ||
|
||
return { | ||
example: example, | ||
exampleWithInput: exampleWithInput | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
# take | ||
## fewer | ||
|
||
@:example(TakeFewer) | ||
Experiment with taking a number of elements from an infinite stream. | ||
|
||
## more | ||
Note that the resulting stream is finite because a fixed number of elements are pulled. | ||
|
||
@:example(TakeMore) | ||
@:exampleWithInput(TakeFromAnInfiniteStream) { | ||
drawChunked = false | ||
} | ||
|
||
## from an infinite stream | ||
|
||
@:example(TakeFromAnInfiniteStream) | ||
## `take` from finite streams | ||
|
||
## from a drained stream | ||
Experiment with taking a number of elements from a finite stream. | ||
|
||
@:example(TakeFromADrainedStream) | ||
@:exampleWithInput(TakeFromAFiniteStream) { | ||
drawChunked = false | ||
} | ||
|
||
## Drained streams | ||
|
||
Drained streams output no elements, but may still capture side-effects. | ||
|
||
@:example(TakeFromADrainedStream) { | ||
drawChunked = false | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2023 Zainab Ali | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package aquascape.examples | ||
|
||
object formCodecs { | ||
given FormCodec[Int] = new FormCodec[Int] { | ||
def attributes: Map[String, String] = Map( | ||
"min" -> "0", | ||
"max" -> "10" | ||
) | ||
def inputType: String = "number" | ||
def encode(i: Int): String = i.toString | ||
def decode(text: String): Option[Int] = | ||
scala.util.Try(Integer.parseInt(text)).toOption | ||
} | ||
} |
Oops, something went wrong.