This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ***Requirements:*** | |
| install TSD | |
| editor atom | |
| express-generator | |
| > express <project name> | |
| > touch app.ts | |
| https://goo.gl/vYexMR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class ProductController{ | |
| async getByPage(offset:number, pageWidth = 50){ | |
| return await factory.getProducts(offset, pageWidth); | |
| } | |
| async get(id:number){ | |
| return await factory.getProductById(id); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface IManusia { | |
| IPakaian Bawahan {get; set} | |
| IBagianTubuh Kaki {get; set;} | |
| IKemaluan Titit {get; set;} | |
| } | |
| interface ILakiLaki : IManusia{ | |
| default void Ngenceh(){ | |
| Bawahan.Find("Resleting").Buka() | |
| Kaki.Ngangkang() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ApiController, Core, val, HttpStatusError, interceptor } from "kamboja" | |
| import { ItemIdCheckInterceptor } from "../interceptor/item-idcheck-interceptor" | |
| import { MongooseHelper } from "kamboja-mongoose" | |
| import { ItemModel } from "../model/item-model" | |
| import { ItemOdm } from "../model/odm" | |
| export class ItemsController extends ApiController { | |
| get( @val.required() id: string) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class StrategyBase { | |
| next() { | |
| return { type: "next" }; | |
| } | |
| exit(result) { | |
| return { type: "exit", result: result }; | |
| } | |
| } | |
| class DefaultStrategy extends StrategyBase { | |
| transform(meta) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| versi C# | |
| class Animal { | |
| speak(){} | |
| } | |
| class Bird : Animal { | |
| fly(){} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Fun<A extends any[], B> = (...args:A) => B | |
| type Cache<T> = {[key:string]: T} | |
| function cache<P extends any[], R>(cache: Cache<R>, fn: Fun<P, R>, getKey: Fun<P, string>) { | |
| return (...args: P) => { | |
| const key = getKey(...args) | |
| const saved = cache[key] | |
| if (!!saved) return saved | |
| else return cache[key] = fn(...args) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function useCache<K, P extends any[], R>(cache: Map<K, R>, fn: (...args: P) => R, getKey: (...args: P) => K) { | |
| return (...args: P) => { | |
| const key = getKey(...args) | |
| const result = cache.get(key) | |
| if(!!result) return result | |
| else { | |
| const newResult = fn(...args) | |
| cache.set(key, newResult) | |
| return newResult | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.use(async (req, res) => { | |
| const user:UserInfo = res.body | |
| //other process use the user data | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //decorator that does noting | |
| function noop(){ | |
| return (...args:any[]) => {} | |
| } | |
| //target | |
| class AnimalClass { | |
| @noop() | |
| list(index:number, limit:number): any[] { | |
| return [] |
OlderNewer