Posts made by justhelpingout
-
RE: C-style #include in TypeScript... possible?
What you probably want is to run everything through TS with the output targeting ES2015+ (or with just imports / exports preserved, if you are targeting <IE11 ... I think that's possible). Then pipe that into RollupJS (which knows how to optimize your code into a single bundle). Finally pipe that into Uglify.
Alternatively, ClosureCompiler now understands
import / export
too, so you could bundle and minify in one go and just have a TS -> CC pipeline. -
RE: Confused about JS promises
You are not fulfilling the contract of
>>=
(which, as you so rightly point out,Promise
mostly fulfills). Your second function (item.client
) is nota -> m b
buta -> void
. Since this is JS, we just go on to the next>>=
call the minuteitem.client
completes (because, right). Change the type of your second function and your third will follow.// Assuming that $.post is a recent version of jQuery it also returns promises // as long as you don't supply the callback parameter .then(() => { item.client.personId(...); // Returning a new promise here properly types this function as `a -> m b` return $.post('/api/clients', clientJson) .then(resp => item.client = ko.mapping.fromJS(resp)); })
Of course, as @ben_lubar points out, you can also just use
async
/await
:const fromJS = ko.mapping.fromJS; const toJSON = ko.toJSON; async function storeItem(item) { item.person = fromJS( await $.post('/api/people/' + item.person.id(), toJSON(item.person)) ); item.client.personId(item.person.id()); item.client = fromJS( await $.post('/api/clients/', toJSON(item.client)) ); item.demographics.personId(item.client.id()); item.demographics = fromJS( await $.post(...) ); }
-
RE: Obsession with Git rebase, how do I survive?
You can actually
git pull --rebase
and all of your commits will be automatically rebased on top of the new remote commits as if you had branched off of theHEAD
of your remote. Here is some more details. -
RE: Scala tutorial for people who can code already
@gÄ…ska
apply
is just a method like any other and it is what is called whenever you seesomeVariable()
- that is,someVariable() === someVariable.apply()
andsomeVariable(1, 2, 3) === someVariable.apply(1, 2, 3)
just like with Java'sFunction
interface.unapply
is used in the extactor portion of acase
expression - if it returns aSome
then the case matched, if it returnsNone
the case is not. The value returned is bound to the inner portion of the LHS of the case:object Extractor { def unapply[T](value: T): Option[Int] = if (value.isInstanceOf[Int]) Option(value.asInstanceOf[Int]) else None } 123 match { case Extractor(boundVar) => boundVar + 3 }
effectively, syntactical sugar for:
var result = null; val cases = List(... LHS and RHS of case statements); for (case : cases) { val bindings = case.LHS.unapply(matchArg); if (!bindings.isEmpty()) { result = case.RHS.evalWithBindings(bindings) break; } }
if you hand-wave a lot :-)
-
RE: Scala tutorial for people who can code already
http://danielwestheide.com/scala/neophytes.html - everything you need and nothing you don't (maybe this will go through this time?)
-
RE: Scala tutorial for people who can code already
@gÄ…ska Check out http://danielwestheide.com/scala/neophytes.html - it goes into some of the more interesting patterns in Scala that you will encounter within 20 (extractors, pattern matching, optional, either) and 40 minutes (type classes, implicits, path-dependent types) respectively.