James Hickey's Blog

Looking At Software Related Ideas Using Short And To The Point Code Samples :)

Menu Close

Page 2 of 2

TypeScript Decorators: Bind Constructor Parameters Automagically

The more I use TypeScript the more I really like it. I’m starting to use the advanced features – and realize how powerful they are. TypeScript decorators are one of those fantastic features that let’s you automate common tasks and apply them in a sort of “meta-programming” fashion.

One of the use-cases I built for a project at work was a class decorator to automate binding a constructor’s parameters as properties on the new object. Read more

It’s The Little Things In Life: Gulp Notifications

I needed a way to issue notifications from gulp / node…

I always have a command line open so I can manually run my gulp tasks. For the project I work on the most at work, our gulp build (on a fast machine) takes around 6 seconds – we’re compiling TypeScript into JavaScript, transpiling that into ES5 compatible code, concatenating third-party scripts, compiling SASS into CSS, adding third-party stylesheets to that, etc. So I suppose 6 seconds isn’t too bad…

When making a tiny change to see if I fixed a bug, or to see a SASS mixin render in the browser, etc. – 6 seconds is a long time to wait until I can refresh my browser. And yes, I’ve tried browser sync – it doesn’t work with our set-up.

And, I found npm package “node-notifier” to be perfect. Read more

Using TypeScript Decorators To Clean-Up Mixins

Lately I’ve been migrating a JavaScript framework I built (for a work client) over to TypeScript. The core UI components are built using mixins. Using jQuery extend(), the JavaScript code would have done something like:

var TextBox.prototype = $.extend({ ...some object with functions and state....}, CanDoExtraStuff, CanDoOtherCoolStuff);

One of the first things I was hoping TypeScript would allow was to clean this up and make it clearer what was going on.

Read more

© 2017 James Hickey's Blog. All rights reserved.

Theme by Anders Norén.