Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View FongX777's full-sized avatar
🎯
Focusing

FongX FongX777

🎯
Focusing
View GitHub Profile
@FongX777
FongX777 / gilded_rose.test.js
Created April 2, 2020 10:50
GildedRose-Refactoring-Kata JS Results
const { Shop, Item, SpecialItemName } = require('../src/gilded_rose');
const { ITEM_AGED_BRIE, ITEM_SULFURAS, ITEM_BACKSTAGE_PASS } = SpecialItemName;
describe('Gilded Rose', function() {
it('the item foo should degrade both its quality and sellIn day', function() {
const gildedRose = new Shop([new Item('foo', 10, 10)]);
const items = gildedRose.updateQuality();
const testItem = items[0];
expect(testItem.name).toBe('foo');
e-commerce
├── catalog
│   ├── applicationService
│   │   ├── AddProduct.ts
│   │   ├── DeleteProduct.ts
│   │   └── UpdateProduct.ts
│   ├── domain
│   │   ├── event
│   │   │   ├── ProductCreated.ts
│   │   │   └── ProductUpdated.ts
@FongX777
FongX777 / either.js
Last active September 16, 2019 06:10
Error Handling in JS
/**
* @param {number[]} nums
* @returns {Left|Right}
*/
function sumPositiveNums(nums) {
if (nums.some(num => !Number.isInteger(num))) {
return Left.of({ code: 501, msg: 'All numbers should be integer' });
}
if (nums.some(num => num <= 0)) {
return Left.of({ code: 502, msg: 'All numbers should be positive'});
@FongX777
FongX777 / all.js
Created July 5, 2019 08:40
Domain Driven Design - JS code sample
/**
* ---------------------------
* Domain Layer
* ---------------------------
*/
class Order {
/**
*
* @param {Object} prop
* @param {string} prop.id
@FongX777
FongX777 / store-product-cacheKeyFn-example.js
Last active March 29, 2019 08:37
Graphql - Dataloader
const { ApolloServer, gql } = require('apollo-server')
const DataLoader = require('dataloader')
const sqlite3 = require('sqlite3').verbose()
const db = new sqlite3.Database(':memory:')
const { promisify } = require('util')
db.get = promisify(db.get)
db.all = promisify(db.all)
// run in serial
db.serialize(function () {