Posts in category “Programming”



Caution: Javascript A || B expression is handy, but it also can cause tricky bug

I had written the following code in a project

   return s && s.value || null

It works well for some days until a colleague did some code refactoring. In the beginning, s.value is a string value, and an empty string is not a valid value, so the code works well. After the refactoring, s.value became an integer, and this time 0 is a valid value. So you can imagine when s.value === 0 the code above will return null instead of 0. It caused a bug!

Therefore please use the"A || B" expression with caution!

Vue.js Event modifier: .stop .prevent .passive .once .self .capture explanation

Two articles explain well this subject. One is in Chinese, the other is in English.

.NET Core 3.1 Swagger UI Tweaks

  1. Present enums as string. Modify your StartUp.cs, add the highlight part below:
             services.AddMemoryCache().AddMvcCore().AddJsonOptions(opts =>
                     opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());

  1. Enable XML Comments
    1. Manually add the two lines in PropertyGroup below to the .csproj file:
    2. Add the options in the code below
           services.AddSwaggerGen(options =>
               options.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{AppDomain.CurrentDomain.FriendlyName}.xml"), true);

SQLSugar: How to implement Count(FieldName) and GROUP BY in SQLSugar

            await Db.Queryable<Entity>().Where(_ => _.SampleFieldName== sampleFieldValue)
                .Select<ResultModel>("AnotherFieldNameInStringFormat, Count(AnotherFieldNameInStringFormat) Total")