-
Notifications
You must be signed in to change notification settings - Fork 2
Add the typeclass IsSendable #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cbd845c
define a class IsSendable to restrict the type of postMessage
gbagan ce98351
update CHANGELOG.md
gbagan 799d7ac
Update Types.purs with purs-tidy
gbagan 5adbf19
add new instances for IsSendable
gbagan e88d349
Merge branch 'main' of https://github.com/gbagan/purescript-web-worke…
gbagan 67b767b
fix a typo in CHANGELOG.md
gbagan e5c2926
add missing exports in Types.purs
gbagan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
, "foreign" | ||
, "functions" | ||
, "maybe" | ||
, "newtype" | ||
, "prelude" | ||
, "unsafe-coerce" | ||
, "web-events" | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,5 +1,51 @@ | ||
module Web.Worker.Types where | ||
module Web.Worker.Types | ||
( MessageEvent | ||
, MessagePort | ||
, Transferable | ||
, SendWrapper | ||
, class IsSendable | ||
, wrap | ||
, unwrap | ||
, unsafeWrap | ||
) where | ||
|
||
import Prelude | ||
|
||
import Prim.RowList (class RowToList, RowList) | ||
import Prim.RowList as Row | ||
import Data.Newtype (class Newtype) | ||
|
||
foreign import data Transferable :: Type | ||
foreign import data MessagePort :: Type | ||
foreign import data MessageEvent :: Type | ||
|
||
class IsSendable (a :: Type) | ||
|
||
instance IsSendable Boolean | ||
instance IsSendable Int | ||
instance IsSendable Number | ||
instance IsSendable Char | ||
instance IsSendable String | ||
instance IsSendable a => IsSendable (Array a) | ||
instance (RowToList r rl, IsSendableRowList rl) => IsSendable (Record r) | ||
instance IsSendable Unit | ||
instance IsSendable Void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify why you added an instance for |
||
instance IsSendable (SendWrapper a) | ||
|
||
class IsSendableRowList (rl :: RowList Type) | ||
|
||
instance IsSendableRowList Row.Nil | ||
instance (IsSendable a, IsSendableRowList rest) => IsSendableRowList (Row.Cons sym a rest) | ||
JordanMartinez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
newtype SendWrapper a = SendWrapper a | ||
|
||
wrap :: forall a b. Newtype a b => IsSendable b => a -> SendWrapper a | ||
wrap = SendWrapper | ||
|
||
unwrap :: forall a. SendWrapper a -> a | ||
unwrap (SendWrapper a) = a | ||
|
||
-- | Use with care. If you send something that isn't actually Sendable, it | ||
-- | will raise an exception. | ||
unsafeWrap :: forall a. a -> SendWrapper a | ||
unsafeWrap = SendWrapper |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there an instance for
Unit
? Can you clarify?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this instance and the instance for Void comes from the library workerbees but I can remove them if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok. I think I missed that.