Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from mint-lang/development
Browse files Browse the repository at this point in the history
3.0.0
  • Loading branch information
gdotdesign authored Sep 9, 2018
2 parents ca16e92 + 8086868 commit 2e42588
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
8 changes: 1 addition & 7 deletions mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,5 @@
],
"external-javascripts": [
"assets/asset-loader.js"
],
"dependencies": {
"mint-core": {
"repository": "https://github.com/mint-lang/mint-core",
"constraint": "0.2.0 <= v < 1.0.0"
}
}
]
}
5 changes: 4 additions & 1 deletion source/AssetLoader.mint
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ module AssetLoader {
}

/* Waits for all promises to load. */
fun loadAll(method : Function(String, Promise(Never, Void)), urls : Array(String)) : Promise(Never, Void) {
fun loadAll (
method : Function(String, Promise(Never, Void)),
urls : Array(String)
) : Promise(Never, Void) {
`Assets.loadAll(method, urls)`
}
}
56 changes: 28 additions & 28 deletions source/CodeMirror.mint
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
component CodeMirror {
/* The JavaScript files of Codemirror to load, either locally or from a CDN. */
property javascripts : Array(String) = [
"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0/codemirror.min.js"
"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0" \
"/codemirror.min.js"
]

/* The CSS files of Codemirror to load, either locally or from a CDN. */
property styles : Array(String) = [
"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0/codemirror.min.css"
"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0" \
"/codemirror.min.css"
]

/* Handler for the change event. */
property onChange : Function(String, Void) = ((value : String) : Void => { void })
property onChange : Function(String, a) = ((value : String) : Void => { void })

/* The content to display until the editor is loaded. */
property loadingContent : Html = Html.empty()
property loadingContent : Html = <></>

/* Whether or not show line numbers. */
property lineNumbers : Bool = true
Expand All @@ -29,8 +31,8 @@ component CodeMirror {
property mode : String = ""

/* Loads all assets when the components mounts. */
fun componentDidMount : Void {
do {
fun componentDidMount : Promise(Never, Void) {
sequence {
AssetLoader.loadAll(AssetLoader.loadScript, javascripts)
AssetLoader.loadAll(AssetLoader.loadStyle, styles)
initializeEditor()
Expand All @@ -48,27 +50,25 @@ component CodeMirror {
}

/* Initializes the editor for the given dom element. */
fun initializeEditor () : Void {
do {
`
(() => {
if (!this.element) { return }
if (this.editor) { return }

this.editor = CodeMirror.fromTextArea(this.element, {
lineNumbers: this.lineNumbers,
theme: this.theme,
mode: this.mode,
})

this.editor.on('change', (value) => {
this.onChange(this.editor.getValue())
})

this.forceUpdate()
})()
`
}
fun initializeEditor : Void {
`
(() => {
if (!this.element) { return }
if (this.editor) { return }

this.editor = CodeMirror.fromTextArea(this.element, {
lineNumbers: this.lineNumbers,
theme: this.theme,
mode: this.mode,
})

this.editor.on('change', (value) => {
this.onChange(this.editor.getValue())
})

this.forceUpdate()
})()
`
}

/* After an update, update the underlying editor instance. */
Expand Down Expand Up @@ -107,7 +107,7 @@ component CodeMirror {
[
<textarea::editor ref={saveReference}/>,
if (`this.editor`) {
Html.empty()
<></>
} else {
loadingContent
}
Expand Down

0 comments on commit 2e42588

Please sign in to comment.