-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
286 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ | |
}, | ||
"dependencies": { | ||
"@emotion/hash": "^0.8.0", | ||
"@rocket.chat/memo": "^0.21.0", | ||
"stylis": "^4.0.6" | ||
} | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/dist |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module.exports = { | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'@rocket.chat/eslint-config', | ||
'prettier', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaVersion: 2018, | ||
warnOnUnsupportedTypeScriptVersion: false, | ||
ecmaFeatures: { | ||
experimentalObjectRestSpread: true, | ||
legacyDecorators: true, | ||
}, | ||
}, | ||
plugins: ['@typescript-eslint', 'prettier'], | ||
rules: { | ||
'func-call-spacing': 'off', | ||
'indent': 'off', | ||
'import/order': [ | ||
'error', | ||
{ | ||
'newlines-between': 'always', | ||
'groups': [ | ||
'builtin', | ||
'external', | ||
'internal', | ||
['parent', 'sibling', 'index'], | ||
], | ||
'alphabetize': { | ||
order: 'asc', | ||
}, | ||
}, | ||
], | ||
'jsx-quotes': ['error', 'prefer-single'], | ||
'no-empty-function': 'off', | ||
'no-extra-parens': 'off', | ||
'no-redeclare': 'off', | ||
'no-spaced-func': 'off', | ||
'no-undef': 'off', | ||
'no-unused-vars': 'off', | ||
'no-useless-constructor': 'off', | ||
'no-use-before-define': 'off', | ||
'operator-linebreak': 'off', | ||
'@typescript-eslint/ban-ts-ignore': 'off', | ||
'@typescript-eslint/func-call-spacing': 'error', | ||
'@typescript-eslint/indent': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-extra-parens': 'off', | ||
'@typescript-eslint/no-redeclare': ['error'], | ||
'@typescript-eslint/no-use-before-define': ['error'], | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': [ | ||
'warn', | ||
{ | ||
allowExpressions: true, | ||
}, | ||
], | ||
'@typescript-eslint/no-unused-vars': 'off', | ||
'@typescript-eslint/no-unused-vars-experimental': 'warn', | ||
'prettier/prettier': 2, | ||
}, | ||
env: { | ||
browser: true, | ||
commonjs: true, | ||
es6: true, | ||
node: true, | ||
jest: true, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
node: { | ||
extensions: ['.js', '.ts', '.tsx'], | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dist |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/dist |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"singleQuote": true, | ||
"semi": true, | ||
"quoteProps": "consistent", | ||
"jsxSingleQuote": true, | ||
"printWidth": 80 | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@rocket.chat/memo", | ||
"version": "0.21.0", | ||
"description": "Memoization utilities", | ||
"keywords": [ | ||
"memoize" | ||
], | ||
"author": { | ||
"name": "Rocket.Chat", | ||
"url": "https://rocket.chat/" | ||
}, | ||
"homepage": "https://github.com/RocketChat/Rocket.Chat.Fuselage#readme", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/RocketChat/Rocket.Chat.Fuselage.git" | ||
}, | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"types": "./dist/esm/index.d.ts", | ||
"files": [ | ||
"./dist/" | ||
], | ||
"scripts": { | ||
"build:esm": "tsc -p tsconfig.json", | ||
"build:cjs": "tsc -p tsconfig-cjs.json", | ||
"build": "run-p build:esm build:cjs", | ||
"eslint": "eslint src", | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/RocketChat/Rocket.Chat.Fuselage/issues" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^16.14.0", | ||
"eslint": "^7.18.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"prettier": "^2.2.1", | ||
"typescript": "^4.1.3" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { memoize, clear } from './memoize'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
type MemoizableFunction<T, A, R> = (this: T, arg: A) => R; | ||
type MemoizedFunction<T, A, R> = (this: T, arg: A) => R; | ||
|
||
const store = new WeakMap< | ||
MemoizableFunction<unknown, unknown, unknown>, | ||
Map<unknown, unknown> | ||
>(); | ||
|
||
const isCachedValue = <A, R>( | ||
cachedValue: R | undefined, | ||
arg: A, | ||
cache: Map<A, R> | ||
): cachedValue is R => cache.has(arg) && cache.get(arg) === cachedValue; | ||
|
||
export const memoize = <T, A, R>( | ||
fn: MemoizableFunction<T, A, R> | ||
): MemoizedFunction<T, A, R> => { | ||
const cache = new Map<A, R>(); | ||
|
||
const memoized: MemoizedFunction<T, A, R> = function (this, arg) { | ||
const cachedValue = cache.get(arg); | ||
|
||
if (isCachedValue(cachedValue, arg, cache)) { | ||
return cachedValue; | ||
} | ||
|
||
const result = fn.call(this, arg); | ||
|
||
cache.set(arg, result); | ||
|
||
return result; | ||
}; | ||
|
||
store.set(memoized as MemoizableFunction<unknown, unknown, unknown>, cache); | ||
|
||
return memoized; | ||
}; | ||
|
||
export const clear = ( | ||
fn: MemoizableFunction<unknown, unknown, unknown> | ||
): void => { | ||
const x = store.get(fn); | ||
|
||
if (x) { | ||
x.clear(); | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "./dist/cjs" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "ES2020", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"sourceMap": true, | ||
"outDir": "./dist/esm", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true | ||
} | ||
} |
Oops, something went wrong.