DivertiseAsia / bs-service-worker

MIT License
0 stars 0 forks source link

Improve Permission module type. #20

Open alias-r opened 4 years ago

alias-r commented 4 years ago

Making permission becomes a module type interface is quite cool. Besides that, I don't quite see the real benefit as it cannot be used against pattern matching.

module Permission : {
  type t;
  let default:t;
  let denied:t;
  let granted:t;
} = {
    type t = string;
    let default:t = "default"
    let denied:t = "denied"
    let granted:t = "granted"
};

e.g. you cannot do this

let x = Permission.default;
switch(x){
|Permission.default => 1
|Permission.denied => 2
|Permission.granted => 3
}
alias-r commented 4 years ago

The best I can do is:

switch(permission){
  | permission when permission == Permission.default => 1
  | permission when permission == Permission.denied => 2
  | permission when permission == Permission. granted => 3
  }
hunterwilliams commented 4 years ago

@alias-r It should end something like the commit so you can switch on it. However locally this is unboxing to denied so I'll take a peek further later.

alias-r commented 4 years ago

https://github.com/DivertiseAsia/bs-service-worker/commit/c13f183cabeb0a7d76abb54887bf50f043bef3ac probably do no require js converter. The recent implementation of BuckleScript translates record directly to Js obj.