blogs's People
blogs's Issues
无需在单元测试中进行太多的mock | Just Blogs
https://thenightmarex.github.io/blogs/2021/08/10/there-is-no-need-to-mock-too-much-in-unit-tests/
之前,我会对要进行单元测试的函数中调用到的所有函数都进行 mock,以确保绝对的“隔离”,然而我最近才察觉 Mock 自己的函数是完全没有必要的 (主要是太麻烦) :假设我要测试 A 函数,A 函数调用了我的 B 函数,但 B 函数也是有其专属的单元测试的,故在对 A 的测试中可以假定 B 函数的运行一切正常,无需 Mock。只有当该函数会产生影响其他测试的、不可或难以复原的副作用:数据库操作、磁
理解Web开发中的前后端 | Just Blogs
浏览一个 Web 页面:浏览器->服务器->数据库->服务器->浏览器其中需要编程的有浏览器上的 HTML、CSS、JS 和服务器上各类语言开发于是我曾这么认为:js 之类的便是前端,django 一类的便是后端直到我学了 Vue……
从函数中返回一个类 | Just Blogs
https://thenightmarex.github.io/blogs/2021/07/16/returning-a-class-from-a-function/
听起来很简单嘛,不就这样么? 1234export function test() { class Inner {} return Inner;} 结果当然是报错了。在这里test()没有注解返回值的类型,那么 TypeScript 自然而然会去推测返回值类型,而返回值是函数内部的不公开类型Inner,declaration 无法在函数外部表示函数内部
基于类的异步Django/DRF视图的实现 | Just Blogs
https://thenightmarex.github.io/blogs/2020/12/06/async-django-views/
最近尝试开发聊天室,需要长轮询或者 WebSocketWebSocket 从来没有涉及过,于是我选择了长轮询不管选哪个,都需要转向使用 ASGI 协议,先把 Channels 装了现在请求-控制是异步的了,视图还是同步的,还是不能写异步代码为了将 DRF 的各种视图转换为异步视图,我选择通过研究 DRF 视图的内部实现,写一个 Mixin 类覆盖/转换关键的同步方法,所有需要转换为异步视图的视图都
.constructor的类型总是Function | Just Blogs
ECMAScript 规定对象的 .constructor 属性保存该对象的构造函数,相当于 Python 中实例的 .class 属性。 对于 Python: 1234class MyClass: passinstance = MyClass() instance 的类型为 MyClassinstance.class 的类型为 Type[MyClass] 而对于 Type
CentOS7宝塔面板部署Django-SQLite项目 | Just Blogs
最近写了人生中第一个 MVT 架构的 Web 应用,部署过程中踩了些坑。
友链申请 - 螓首蛾眉
标题:螓首蛾眉
地址:https://jsun969.cn
描述:好看的皮囊千篇一律,有趣的灵魂万里挑一
头像:https://unpkg.zhimg.com/[email protected]/avatar.jpg
资瓷资瓷23333
返回400还是403? | Just Blogs
https://thenightmarex.github.io/blogs/2021/07/17/http-code-400-or-403/
对于POST /applications/ { "chatroom": }接口,如果该用户先前已经创建了一个加入该聊天室的申请,且该申请还未被处理,则应拒绝该请求,在这种情况下,应该返回400还是403呢?
`this`也是一个类型 | Just Blogs
https://thenightmarex.github.io/blogs/2021/04/20/this-is-also-a-type/
这两个接口是等价的 123interface Test<T1, T2, T3, T4> { returnThis(): Test<T1, T2, T3, T4>;} 123interface Test<T1, T2, T3, T4> { returnThis(): this;}
`const`类型断言 | Just Blogs
https://thenightmarex.github.io/blogs/2021/06/07/const-type-assertion/
as const 将原类型断言为不可变类型(只读类型),在一些特定场景下需要用到。
关于 | Just Blogs
https://thenightmarex.github.io/blogs/about/
我是 Charles,一名 Web 全栈开发者、工具库作者。高中在读,成绩上游,初二接触编程,初三入门 Web。 我追求极致工程化。不论是变量名、换行空行、提交记录还是项目架构,我都会充分斟酌直到自己真正满意;对于杂乱的实现,我会果断重构,将代码的质量和可读性提升至我能达到的最高水平。一年中,从学着写 HTML、CSS、JavaScript 的小萌新,到能够独立完成前端后端、造轮子填补生态空白、为
错误消息风格 | Just Blogs
https://thenightmarex.github.io/blogs/2021/10/04/error-message-style/
只用一句话 Cannot access this department, because you are not a member of it X Cannot access departments of which you are not a member √ 不使用句号结尾 Must authenticate first. X Must authenticate first 使用 “
你真的需要访问控制吗 | Just Blogs
https://thenightmarex.github.io/blogs/2021/10/04/do-you-really-need-access-control/
需要 但不完全需要 对于广义上的访问控制,控制一个操作是否可以执行,当然必须绝对完全需要对于狭义上的访问控制,RBAC、CBAC 之类的访问控制,在大部分情况下是不需要的 RBAC、CBAC 对于大部分的 WebApp 而言,是既不合算也不适合的。你只需要在执行操作前加几个 if (xxx) throw xxx 就可以了。
RESTful接口关系字段最佳实践 | Just Blogs
https://thenightmarex.github.io/blogs/2021/08/11/best-practice-of-relation-fields-in-restful-api/
虽然这属于常识性问题,但对于后端开发入门者而言,关系字段的处理还是很容易出现各种奇怪的问题。
从构造函数中显式返回一个值 | Just Blogs
https://thenightmarex.github.io/blogs/2021/07/22/returning-value-explicitly-from-a-constructor/
构造函数中是可以显式返回一个值的。对于 JavaScript,只要求返回值是一个对象即可,否则依然返回实例;对于 TypeScript,则要求返回值的类型必须可赋给类的实例类型。 利用这一特性,可以实现很多有意思的东西。
在复杂类型计算中保存中间状态 | Just Blogs
假设我们有一个 ExtractKeys 工具类型用来提取一个对象中对应的值满足条件的所有键: 123type ExtractKeys<Obj, ValueType> = { [Key in keyof Obj]: Obj[Key] extends ValueType ? Key : never;}[keyof Obj]; 如果有一个新类型要实现仅在指定键也满足条
tags | Just Blogs
补充声明`process.env`的类型 | Just Blogs
https://thenightmarex.github.io/blogs/2021/04/18/declaring-type-of-process-env/
12345678declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace NodeJS { export interface ProcessEnv { key: string; } }}
类型严格的装饰器 | Just Blogs
https://thenightmarex.github.io/blogs/2021/10/04/strictly-typed-decorators/
类型严格的装饰器?装饰器还能怎么类型严格? 事实上,装饰器不仅可以限制选项的类型,还可以限制目标类的类型。而对于属性装饰器和方法装饰器,还可以限制目标属性名的类型(string、number、symbol),更强大的是,还可以限制目标属性值的类型。
在NestJS中使用管道验证一切 | Just Blogs
https://thenightmarex.github.io/blogs/2021/07/17/using-the-pipe-to-validate-everything-in-nestjs/
nest 与 class-validator 可以完美整合,对于数据结构、类型的验证,nest 和 class-validator 都有详细的文档,在此不再赘述。然而需要验证的不止有数据结构和字段类型,还有各式的业务需求,这是没有文档提及的。大多数的 nest 使用者选择直接在 services 中进行数据验证,但这样就导致了不优雅的高耦合的代码, nest 推荐使用 pipes 集中验证数据 ,
史上最完美的 Vuex 4 类型声明 | Just Blogs
https://thenightmarex.github.io/blogs/2021/07/27/super-awesome-vuex-type-declaration/
记得上一次写 Vue 还是在刚刚接触 TypeScript 的时候,这一整个高一下学期我都在为课题研究的 Web 项目不停地造轮子,由于强迫症的作用,我总爱把类型写得面面俱到,能写成字面量类型的字符串绝不用 string 类型一带而过,于是不经意间对 TypeScript 的理解便提升了不止一个档次。 前两天我终于初步完成了后端。来到久违的前端,突然想起了 Vuex 恐怖的 TypeScript
Jest解析TS非相对路径模块导入 | Just Blogs
https://thenightmarex.github.io/blogs/2021/04/18/resolve-ts-non-relative-imports-for-jest/
Typesciprt 提供compilerOptions.baseUrl选项来配置导入非相对路径模块时的根路径 123456// tsconfig.json{ "compilerOptions": { "baseUrl": "./" }} Typescript 可正常编译,但 Jest
HTML中的`script`标签 | Just Blogs
https://thenightmarex.github.io/blogs/2020/10/25/script-labels-in-html/
<script> 已经衍生出多种加载方式:Prettier格式化中使每个数组元素位于单独的一行上 | Just Blogs
Prettier 对 multi-line objects 的格式进行了特殊优化,使其在没有超过长度限制的情况下可以根据左花括号后是否紧跟换行而变化格式(超过长度限制则强制格式化为多行)。然而很迷惑的是,其却没有对 multi-line arrays 也进行特殊优化: 12345678910111213141516171819// dynamic: single-line or multi-lin
不要用MikroORM中Filter的第二个参数替代鉴权 | Just Blogs
MikroORM 的 Filter 无疑是其一大特色,可以很方便地控制用户可见资源。 其 cond 回调可以接受第二个参数 type: 'read' | 'update' | 'delete',聪明蛋们肯定想到可以根据 type 来动态控制: 1234567891011@Filter({ name: "crud",
Vue-CLI项目不跨域调试调试后端 | Just Blogs
https://thenightmarex.github.io/blogs/2020/11/10/debug-vue-projects-without-cors/
Django Development Server: http://localhost:8000Vue Development Server: http://localhost:8080 无需配置跨域,通过 vue-cli配置代理即可实现将发往 localhost:8000/api 的请求转发到 localhost:8080/api。
定义类的属性初始值 | Just Blogs
https://thenightmarex.github.io/blogs/2021/06/07/defining-default-value-of-class-properties/
属性初始值的赋值发生在构造函数调用之前,定义类的属性初始值时是可以访问某些对象的
声明Vuex中store类型的更好方法 | Just Blogs
https://thenightmarex.github.io/blogs/2021/07/26/better-way-to-declare-the-type-of-vuex-store/
这不就完了吗?? 12345678910111213import { createStore } from "vuex";const store = createStore({ state: { key: "value", },});export default store;declare
declare module 语句在 .d.ts 和 .ts 文件中效果不同 | Just Blogs
在 .ts 文件中,declare module 作补充类型声明的作用,声明的类型会被合并到该模块的原类型声明中。 在 .d.ts 文件中,declare module 作类型声明的作用,声明的类型会覆盖该模块的原类型声明。
为什么前端也需要ORM | Just Blogs
https://thenightmarex.github.io/blogs/2021/08/11/why-does-the-frontend-also-need-orm/
ORM(Object Relational Mapping),指对象关系映射。但在后端,ORM 通常指一个用来操作数据库的 Lib,除了对象关系映射以外,通常还包含了 SQL 语句生成、数据库表建模等等。前端所需要的 ORM 不用那么多杂七杂八的附加功能,只需要对象关系映射这一最基本的功能就够了。
阻止 Angular Material 中涟漪效果的冒泡传播 | Just Blogs
继承Function的类 | Just Blogs
https://thenightmarex.github.io/blogs/2021/07/22/classes-that-extend-function/
ES6 的 class 允许继承Number、String、Function等内置特殊类,于是尝试了一下继承Function,虽说并没有很大的实际意义。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.