Awesome
Kefjs
A Kotlin/JS Wrapper for ef.js.
Related project:
Usage
Import Kefjs from CubeSky Repo with Maven or Gradle.
Ef.setParser(ParserMethod) //Change the default parser for ef.js so you can use a different type of template
Ef.parseEft('Your awesome template') //Get ef.js ast using default parser
val templateString = "Your awesome template"
val ast = arrayOf(/* AST Which Support by ef */)
val template1 = Ef.create(template)
val template2 = Ef.create(ast)
val template3 = """
Your awesome template
""".prepareEf()
val component1 = template1.newInstance()
val component3 = template3.newInstance(kefconfig {
data {
key setTo value
}
methods {
methodName bind { state, value, e ->
} // same as ef.js component1.$methods.key = function ({state, value, e}) {}
}
})
Ef.onNextRender(MethodFunction) // Cache operations to execute on next render
Ef.inform() // Tell ef to cache operations **USE WITH CARE**
Ef.exec() // Tell ef to execute all cached operations **USE WITH CARE**
Ef.exec(true) // Force execute cached operations **USE WITH CARE**
Ef.bundle(MethodFunction) // Wrapper for Ef.inform() and Ef.exec()
component1.getElement() // The DOM element of component1
component2.getElement() // The DOM element of component2
component1.data["something"] = "Something new" // Update Binding Data
component2.methods["someMethod"] = Ef.createFunc { state, value ,e ->
state.data["something"] = "Something new"
println("Event target ${e.target}")
println("Value passed $value")
})
val logData = Ef.createFunc { state, value ,_ ->
println("Subscribed data updated: $value")
}
component1.subscribe("info.data", logData) // Observe a value
component1.unsubscribe("info.data", logData) // Stop observing a value
component2.getParent() // Get where the component is mounted
component2.getRefs("example") // Get referenced nodes named 'example'
component1.mount("mountingPoint",component2) // Mount component2 to 'mountingPoint' on component1
component1.mount("mountingPoint",null) // Detach the mounted component
component1.list("listMP").push(component2) // Mount component2 to list 'listMP' mounting point on component1
component1.mount(target, option) // Mount method called by ef when trying to mount
component1.umount() // Unmount from parent
Experimental
These feature is provide by Kefjs. Maybe not stable or maybe not recommended by ef.js
author.
- Data Store in Ef instance
component1.editUserStore(key, value) //key is String, value is Any, pass null to value can remove this key. component1.getUserStore(key, default) //get value or default