Skip to content

Instantly share code, notes, and snippets.

@wirthi
Created December 19, 2019 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wirthi/92776f6983decd5b3f53a8490c72a073 to your computer and use it in GitHub Desktop.
Save wirthi/92776f6983decd5b3f53a8490c72a073 to your computer and use it in GitHub Desktop.
React.js blogpost
- dieIf(!result.isArray, "Not an array")
- dieIf(!result.hasSlot(0), "No slot 0")
- dieIf(!result.hasSlot(1), "No slot 1")
- dieIf(result.hasSlot(2), "Has slot 2")
+ dieIf(!result.hasArrayElements, "Not an array")
+ dieIf(result.getArraySize != 2, "Array of size != 2")
- val elem0 = result.getSlot(0)
- dieIf(!elem0.isInstanceOf[String], ...)
- val safeHtml = elem0.asInstanceOf[String]
+ val elem0 = result.getArrayElement(0)
+ dieIf(!elem0.isString, ...)
+ val safeHtml = elem0.asString
- val elem1 = result.getSlot(1)
- dieIf(!elem1.isInstanceOf[ScriptObjectMirror], ...)
- val mentionsArrayMirror = elem1.asInstanceOf[ScriptObjectMirror]
+ val elem1 = result.getArrayElement(1)
+ dieIf(!elem1.hasArrayElements, ...)
+ val mentionsArrayMirror = elem1
val mentions = ArrayBuffer[String]()
var nextSlotIx = 0
- while (mentionsArrayMirror.hasSlot(nextSlotIx)) {
- val elem = mentionsArrayMirror.getSlot(nextSlotIx)
- dieIf(!elem.isInstanceOf[String], ...)
- mentions.append(elem.asInstanceOf[String])
- nextSlotIx += 1
- }
+ while (nextSlotIx < mentionsArrayMirror.getArraySize) {
+ val elem = mentionsArrayMirror.getArrayElement(nextSlotIx)
+ dieIf(!elem.isString, ...)
+ mentions.append(elem.asString)
+ nextSlotIx += 1
+ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment