profile
viewpoint
忽如寄 huruji @ByteDance @sysu Shenzhen http://tink.greywind.xyz 忽如寄也叫灰风GreyWind。 want to be a hero one day,a problem solver,not only a programer

startedzsh-users/zsh-syntax-highlighting

started time in 7 hours

startedflutter/plugins

started time in 9 hours

push eventhuruji/react-pretty-check

huruji

commit sha a5b1f313f253cf553e8b91304ee7aeec52084569

feat: :tada: init

view details

push time in 10 hours

create barnchhuruji/react-pretty-check

branch : master

created branch time in 12 hours

created repositoryhuruji/react-pretty-check

pretty-check for react

created time in 12 hours

startedWoodNeck/css-camera

started time in 13 hours

startedmacports/macports-base

started time in 19 hours

startedbytedance/unpub

started time in 20 hours

startedLiveLikeCounter/Flutter-Todolist

started time in a day

push eventhuruji/rumi

huruji

commit sha ff9820e5fc3cd5e692f1ce6bf4f09f1df5842a10

feat: :tada: init project

view details

huruji

commit sha 46ab87fc83d36dea813602de2203fc4607494b76

feat: :tada:

view details

push time in a day

fork huruji/TODOAppUI

TODO App Concept UI

fork in a day

push eventhuruji/micat

huruji

commit sha a7b10c6043a71d85175c86d3f2e3a835e3a617ea

feat: :lipstick: style of setting

view details

push time in a day

startedgabrielbull/react-desktop

started time in 2 days

startedweolar/miniblink49

started time in 2 days

startedHFO4/gameboy.live

started time in 2 days

startedmitesh77/Best-Flutter-UI-Templates

started time in 2 days

startedCasterWx/python-girlfriend-mood

started time in 2 days

startedCasterWx/AntzOS

started time in 2 days

startedremaxjs/remax

started time in 2 days

startedegoist/vue-windows

started time in 3 days

startedegoist/snackbar

started time in 3 days

startedyifeikong/reverse-interview-zh

started time in 3 days

startedquickjs-zh/QuickJS

started time in 4 days

startedreact-icons/react-icons

started time in 4 days

startedHeskeyBaozi/reduce-antd-icons-bundle-demo

started time in 4 days

startedmikaelbr/node-osascript

started time in 4 days

issue openedhuruji/blog

Dart 异步编程之 Future

Dart 中 Future 类似于 JavaScript 中的 Promise,类似于 Promise,Future 可以通过两个方式 completed,分别是 succeed 和 fail,相当于 Promise 里的 fullfilled 和 rejected。

简单的构造一个 Future 实例:

Future(() => 12)

当 Future completed 的时候可以通过 then 来执行下一步,如:

  Future.delayed(Duration(seconds: 3), () => 12)
      .then((value) => value + 1)
      .then((value) => print(value));

最终打印 13

当然也可以使用 catchError 来捕获异常:

  Future.delayed(Duration(seconds: 3), () => {throw 'error'})
      .then((value) => print('success'))
      .catchError((e) {
        print(e);
        return 'future 2';
      });

如果需要捕获单次 Future 实现如 Promise 如下的效果:

new Promise(resolve => resolve()).then().catch()

可以使用 then 的命名参数 onError

  Future.delayed(Duration(seconds: 3), () => {throw 'error'}).then((value) {
    return 'success';
  }, onError: (err) {
    return 'fail';
  }).then((val) => print(val));

这时候打印 fail

除此之外,还有其他构造函数,如创建一个以 error 完成的 Future,类似于 Promise.reject

  Future.error((err) => 'huruji').then((value) {
    return 'success';
  }, onError: (err) {
    return 'fail';
  }).then((val) => print(val));

这时候打印 fail.

类似 Promise.resolve 可以使用 Future.value

Future.value(12).then((value) {
    print(value);
  });

如果想要立即执行一个 computation 函数,可以使用 Future.sync,如果需要延迟执行可以使用 Future.delayed

  Future.sync(() => 12).then(print);

  Future.delayed(Duration(seconds: 2), () => 12).then(print);

除了这些构造函数以外,一个 Future 实例还有 .then() .catchError() .whenComplete(),这些都和 Promise 类似,whenComplete 类似于 finally,此外,还有 .timeout 方法,类似于构造函数 Future.delayed

Future(() => 12).timeout(Duration(seconds: 3)).then(print);

当然,还提供了一些对应的静态方法,Future.any 对标 Promise.race

  Future.any([
    Future.delayed(Duration(seconds: 2), () => 12)
        .then((val) => throw 'huruji'),
    Future.delayed(Duration(seconds: 5), () => 15)
  ]).then((val) => print(val), onError: (e) {
    print(e);
    print('faile');
  });

Future.wait 对标 Promise.all

  Future.wait([
    Future.delayed(Duration(seconds: 2), () => 12),
    Future.delayed(Duration(seconds: 5), () => 15)
  ]).then((val) => print(val));

Future.doWhile 重复执行知道返回 false,

Future.forEach 顺序拿到对应的 future(同时执行只是顺序拿值而已):

  Future.forEach([
    Future.delayed(Duration(seconds: 6), () => 12),
    Future.delayed(Duration(seconds: 10), () => 15)
  ], (f) => f.then(print));

created time in 4 days

startedhubvue/Micro-FE

started time in 4 days

issue commenthuruji/JDS_weekly

微前端相关

https://martinfowler.com/articles/micro-frontends.html#Server-sideTemplateComposition

huruji

comment created time in 4 days

startedCanopyTax/single-spa

started time in 5 days

startedharveyaot/DianJing

started time in 5 days

issue openedhuruji/JDS_weekly

微前端相关

https://medium.com/@benjamin.d.johnson/exploring-micro-frontends-87a120b3f71c

created time in 5 days

startedthompsongl/postcss-class-prefix

started time in 5 days

startedumijs/qiankun

started time in 5 days

startedatomiks/tippyjs

started time in 5 days

startedatian25/blog

started time in 5 days

startedsindresorhus/type-fest

started time in 5 days

startedxmppjs/xmpp.js

started time in 5 days

starteddaumann/ECMAScript-new-features-list

started time in 5 days

push eventhuruji/set_timeout

huruji

commit sha 60ac019ac19dc3137fa5abd27b12109e63eb29af

feat: :tada:

view details

push time in 5 days

create barnchhuruji/set_timeout

branch : master

created branch time in 5 days

created repositoryhuruji/set_timeout

setTimeout implemented by Dart

created time in 5 days

push eventhuruji/timeago

huruji

commit sha c25f3c70cb64221195903f92c8167debc581e447

feat: :tada: simple implement

view details

push time in 5 days

create barnchhuruji/timeago

branch : master

created branch time in 5 days

created repositoryhuruji/timeago

timeago implemented by Dart

created time in 5 days

issue openedhuruji/blog

Dart 的 DateTime

Dart 通过 DateTime 来处理时间,DateTime 构造函数可以可以根据传入的参数构造一个 DateTime 实例,DateTime.now 构造函数返回本地时区当前时间的 DateTime 对象.

DateTime(int year, [ int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0 ])

同时,Dart 也提供了 DateTime.utc 构造函数来构造一个 utc DateTime 对象:

DateTime.utc(int year, [ int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0 ])

DateTime 对象提供了获取档期时间对象的年份、月份、每个月的第几天、小时、星期几等属性,其中月份从1开始,星期从1开始(星期一为1,星期天为7)等:

  DateTime date = DateTime.now();

  print(date.day); // 15
  print(date.hashCode); // 326917132
  print(date.hour); // 21
  print(date.isUtc); // false
  print(date.microsecond); // 379
  print(date.minute); // 54
  print(date.month); // 9
  print(date.second); // 28
  print(date.timeZoneName); // CST
  print(date.timeZoneOffset); // 8:00:00.000000
  print(date.weekday); // 7
  print(date.year); // 2019

DateTime 对象同时提供了 add 方法来返回一个新的 DateTime 对象,add 方法接受一个 Duration 对象,因为 Duration 对象可以为负的,所以 add 方法可以返回一个之前时间的 DateTime 对象。

  DateTime nextDay = date.add(Duration(hours: 24));
  DateTime prevDay = date.add(Duration(hours: -24));
  print(nextDay.day); // 16
  print(prevDay.day); // 14

对比两个 DateTime 对象可以使用 compareTo 方法:

  print(prevDay.compareTo(nextDay)); // -1
  print(nextDay.compareTo(prevDay)); // 1
  print(prevDay.compareTo(prevDay)); // 0

更方便的方法是使用 isAfter isBefore isAtSameMomentAs 来对比是否比时间更晚、更早、相同。

  print(prevDay.isAfter(nextDay)); // false
  print(prevDay.isBefore(nextDay)); // true
  print(prevDay.isAtSameMomentAs(prevDay)); // true

当然如果需要更详细的两个时间对比,使用 difference 方法可以返回两个 DateTime 对象的时间差,是一个 Duration 对象:

  print(prevDay.difference(nextDay));

DateTime 对象同时提供了月份,星期的常量:

  print(DateTime.monday); // 1
  print(DateTime.april); // 4

created time in 5 days

issue openedhuruji/blog

Dart 的 Duration

Duration 顾名思义就是指的一段时间,用 Duration 类可以构造一段时间的对象,Duration 对象实例化的参数非常通俗易懂,可以传入对应的天、时、分、秒、毫秒、微秒 来构造对应的时间段。

Duration({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, int milliseconds: 0, int microseconds: 0 })

如:

Duration fast = Duration(minutes: 123, hours: 24);
Duration slow = Duration(hours: 20);

实例可以通过 inDays inHours inMinutes 等属性返回该时间段转换为天数、小时、分钟等,此时为向下取整。

Duration fast = Duration(minutes: 123, hours: 24);
print(fast.inDays); // 1

实例化时是可以传入负数的,Duration 也提供了 abs() 方法来获取对应的绝对值:

  Duration ne = Duration(hours: -24);
  print(ne.inDays); // -1
  print(ne.abs().inDays); // 1

比较两个 Duration 对象的大小可以使用 compareTo 方法,如果相等则返回0,大于则返回1,小于则返回 -1,

  Duration fast = Duration(minutes: 123, hours: 24);
  Duration slow = Duration(hours: 20);

  print(fast.compareTo(slow)); // 1
  print(slow.compareTo(fast)); // -1
  print(fast.compareTo(fast)); // 0

更方便的方法是使用操作符,Duration 对象支持 + 、-、*、<、<=、==、>= 、> 等操作符号,乘法操作符另一个乘数是一个整数,而不是 Duration 对象:

除此之外,Duration 还提供了一些常量,如:hoursPerDay、minutesPerDay,hoursPerDay 永远等于 24。

created time in 5 days

startedthepracticaldev/dev.to

started time in 6 days

push eventhuruji/micat

huruji

commit sha 6c45f9aef7486c701a2bf589b6506130b7684694

chore: :wrench: add dev script

view details

push time in 6 days

push eventhuruji/micat

huruji

commit sha 2c605ecd96dd7356ca80995ff4e1f9a4e59822d9

feat: :sparkles: :lipstick: add autochange modal

view details

push time in 6 days

startedPopmotion/popmotion

started time in 6 days

startedqieguo2016/iconoo

started time in 6 days

startedegoist/devdocs-desktop

started time in 7 days

starteddianping/cat

started time in 7 days

startedbrianegan/transparent_image

started time in 7 days

startedflutterchina/dio

started time in 7 days

startediampawan/FlutterExampleApps

started time in 8 days

startedsteveukx/commands.js

started time in 8 days

push eventhuruji/saso

huruji

commit sha 904ce7e25d16bd136cf56f68799420e6cddd0609

feat: :construction: add v8 cache

view details

push time in 9 days

fork huruji/luban-h5

en: A mobile page builder/editor, similar with amolink. zh: 类似易企秀的H5制作、建站工具.

https://api.luban-h5.wxjcart.com

fork in 9 days

startedly525/luban-h5

started time in 9 days

startedoliver-moran/jimp

started time in 9 days

startedegoist/node-vs-deno

started time in 10 days

startedbimsina/wallpaper

started time in 10 days

startedtortuvshin/open-source-flutter-apps

started time in 10 days

startedspencermountain/spacetime

started time in 10 days

startedzertosh/v8-compile-cache

started time in 10 days

startedsindresorhus/boxen

started time in 10 days

startedSaul-Mirone/type-config

started time in 10 days

push eventhuruji/update-notifier2

huruji

commit sha 68974b9ab85b577d68619e11bbd8f3fc1877bf28

docs: :memo:

view details

push time in 10 days

push eventhuruji/latest-version2

huruji

commit sha 6e59aaa15781492c9a19669bb2f8934f3d36131f

feat: 添加 npm 私服支持

view details

push time in 10 days

push eventhuruji/update-notifier2

huruji

commit sha bd09a77c3693a57e0b122d8a1fd0a8c21020f9aa

feat: :sparkles: 添加 npm 私服支持,和 installCommand 配置

view details

push time in 10 days

fork huruji/latest-version

Get the latest version of an npm package

fork in 10 days

fork huruji/registry-url

Get the set npm registry URL

fork in 10 days

fork huruji/update-notifier

Update notifications for your CLI app

fork in 10 days

push eventhuruji/react-modal-image2

huruji

commit sha 2598f9662332eced28a182edb1420bdfb4645c05

feat: :sparkles: add onOpen onClose

view details

push time in 11 days

startedJohnPostlethwait/fixme

started time in 11 days

startedGenymobile/scrcpy

started time in 11 days

fork huruji/react-modal-image

A tiny React component providing modal image Lightbox.

https://aautio.github.io/react-modal-image/

fork in 11 days

startedmysticatea/vue-eslint-parser

started time in 12 days

startedalexreardon/memoize-one

started time in 12 days

startedburakson/sherlogjs

started time in 13 days

startedCommanderXL/vue-template-ast-to-template

started time in 13 days

startedktsn/vue-ast-explorer

started time in 13 days

startedfacebook/jscodeshift

started time in 13 days

issue commentaxios/axios

No statusText on Chrome

is it a bug of chrome?

FlandreDaisuki

comment created time in 14 days

startedDamonOehlman/detect-browser

started time in 15 days

startedericwindmill/flutter_by_example_apps

started time in 15 days

startedHackSoul/zhihu-flutter

started time in 15 days

fork huruji/DeepMosaics

Automatically remove the mosaics in images and videos, or add mosaics to them.

fork in 15 days

startedkatspaugh/wavesurfer.js

started time in 16 days

created taghuruji/saso

tagsaso-template-typescript@1.0.3

Zero config bundler to help you to build fantastic APP

created time in 16 days

push eventhuruji/saso

huruji

commit sha 3fe24572b08a435c509622bb572cf3fcbe753b19

fix: template bug

view details

huruji

commit sha 888b039247b8266ff1c6406267d3086f445b0106

chore: :wrench: add pub script

view details

huruji

commit sha f2138910d24ec89501eb3450b6145c45181ea7b7

chore: :bug: package.json

view details

huruji

commit sha d6ca5b0b83130c4529a18dcffaeb3e412e58127e

chore(release): publish - saso@4.0.1 - saso-template-typescript@1.0.3

view details

push time in 16 days

created taghuruji/saso

tagsaso@4.0.1

Zero config bundler to help you to build fantastic APP

created time in 16 days

push eventhuruji/saso

huruji

commit sha 3b22507ab64ea05c1a9428af512f4094de6dcc11

docs: :memo: add init doc

view details

push time in 16 days

startedcube-js/cube.js

started time in 16 days

startedgrafana/grafana

started time in 16 days

push eventhuruji/micat

huruji

commit sha 0545280a957b843e1114e16f7eca2a999c7c1549

feat: :bug: exit right click

view details

huruji

commit sha 7277a772e06d4a85aecd915f4041c062945e4fbd

feat: :sparkles: add loading when setting

view details

push time in 16 days

startedbenjaminadk/emojigit

started time in 18 days

startediperov/DeepFaceLab

started time in 18 days

more