Reputation: 17997
I want to write make my controller with inheritance using sails.js node module.
I use Typescript to write my javascript, object oriented.
I tried, few weeks/months ago to do it but I failed, I want to try again because I know more TS and nodejs/sails.js by now. But I'm wondering if it's possible, because I don't know sails.js by heart and it could not be possible depending on the way the controllers are loaded.
Is there any example of this? With or without typescript.
I also think that TS files have to be compiled in CommonJs and not with AMD, because at the time the controllers are loaded, the config/bootsrap.js is not loaded and the libraries such as requirejs are not loaded, so require AMD files will fail.
Upvotes: 3
Views: 1609
Reputation: 17997
Since I asked that question about a year ago, I've made my own implementation of Sails with TypeScript.
https://github.com/Vadorequest/sails-typescript
Upvotes: 2
Reputation: 1196
That's basically your own implementation. You could use typescript or (eww) coffeescript. Or, if your javascript foo is good enough write it yourself. Sails is just javascript, using express, which also is javascript. So inheritance is possible, but up to you to implement (most people don't need it). I'm not sure if everyone agrees with me on this, but it is what I think.
Besides that, you could use ES6-module-loader to write up your imports according to the current draft of the ES6 proposal. That way, once it's ready, you get to remove the dependency and already play around with imports (which you could then use in combination with classes to write up extended classes).
It doesn't matter in what order sails loads your controllers. At the end of the day it's just javascript, and you can just import your own abstract class.
Upvotes: 4