Dependency injection in TypeScript

I have developed an IoC container called InversifyJS with advanced dependency injection features like contextual bindings. You need to follow 3 basic steps to use it: 1. Add annotations The annotation API is based on Angular 2.0: import { injectable, inject } from “inversify”; @injectable() class Katana implements IKatana { public hit() { return “cut!”; … Read more

How to refer to Typescript enum in d.ts file, when using AMD?

The best solution may depend on whether you have a preference for the actual JavaScript variable being a number, a string, or otherwise. If you don’t mind String, you can do it like this: ///messagelevel.d.ts export type MessageLevel = “Unknown” | “Fatal” | “Critical” | “Error”; ///main.d.ts import * as ml from “./MessageLevel”; interface IMyMessage … Read more

supporting both CommonJS and AMD

Yes, and I owe this answer to ded and his awesome modules: (function(name, definition) { if (typeof module != ‘undefined’) module.exports = definition(); else if (typeof define == ‘function’ && typeof define.amd == ‘object’) define(definition); else this[name] = definition(); }(‘mod’, function() { //This is the code you would normally have inside define() or add to … Read more

Expire cache on require.js data-main

How are you defining your require.config? I think for it to take effect before you import require.js, you need to code it like this: <script type=”text/javascript”> var require = { baseUrl: “/scripts/”, waitSeconds: 15, urlArgs : “bust=”+new Date().getTime() }; </script> <script data-main=”app/main” src=”https://stackoverflow.com/scripts/require.js”></script> Specifically, a an object named ‘require’ must be constructed before you import … Read more

Why do we need a Single Page Application? [closed]

I believe that this is the direction most websites should be moving in considering the number of devices that users utilize today, and the abilities and limitations of each. IMPORTANT: Before reading the rest of this, please understand that this concept is built on the foundation of basic principles of designing for the web. In … Read more

How to stop babel from transpiling ‘this’ to ‘undefined’ (and inserting “use strict”)

For Babel >= 7.x ES6 code has two processing modes: “script” – When you load a file via a <script>, or any other standard ES5 way of loading a file “module” – When a file is processed as an ES6 module In Babel 7.x, files are parsed as “module” by default. The thing that is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)