We are going to add another feature: the chance to evaluate arbitrary code and see its result in a dedicated area.
This will be achieved by taking what the user is looking at, typically a small function, preprending to it some imports and then appending a main where user input is appended to look like
main = logShow $ USER_CODE_APPENDED_HERE
and then reassigning JavaScript's console.log
to a function that would look something like
window.console.log = function(result) {
return function(selector) {
$(selector).val(result)
}
}
So that we have some sort of REPL.
So the error I was doing shows how little I understand about ClojureScript, I was passing around a ClojureScript map {}
while instead I needed a JavaScript object #js {}
or (js-obj)
.
I needed this in the following code:
(defn create-mocha-context
"creates a context in which all required functions and
variables are defined, so mocha can run fine.
it does this by passing a mocha-context as payload to
pre-required event, mocha-context is then enriched with
all required functions, like it before after describe etc"
[]
(def Mocha (node/require "mocha"))
(let [mocha-context #js {} ;; ** THIS IS THE IMPORTANT LINE **
mocha (Mocha. {:reporter "reporter"})]
(.emit (.-suite mocha) "pre-require" mocha-context nil mocha)
(.createContext vm mocha-context)))
In the "important line" I was passing {}
instead, which is immutable because it's a ClojureScript data structure
so I was getting back {}
from the function invocation, instead of the whole thing.
In the end I managed to mutate the contents of a file in memory, now I just need to cleanup the project ready for the presentation on Thursday, which means:
- write a series of steps runnable from src/cerebro/core.cljs
- polish the introduction to mutation testing addressing the code coverage fail scenario
One of the things I would love to do in the very next future is introduce deftype
where needed in the codebase, so my
data handling can be easier, I still have to see how does that translates in JavaScript though.
- Cerebro
- project lamp
- still need some attention needed for timsort, radix sort, dijkstra algo
- chapter 3 of the little schemer in Clojure
- allow some time to think
- find a new apartment