Skip to content

Commit

Permalink
Add rxjs. Add update function.
Browse files Browse the repository at this point in the history
  • Loading branch information
sliptype committed Oct 14, 2018
1 parent d6dd297 commit 6e8e5b5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"author": "[email protected]",
"license": "MIT",
"dependencies": {
"rxjs": "^6.3.3",
"rxjs-compat": "^6.3.3",
"snabbdom": "^0.7.2"
}
}
4 changes: 3 additions & 1 deletion psc-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "purescript-meiosis",
"set": "0.12.0-20181005",
"set": "0.12.0-20181014-4",
"source": "https://github.com/sliptype/package-sets.git",
"depends": [
"control",
"rxps",
"ordered-collections",
"snabbdom",
"maybe",
Expand Down
19 changes: 15 additions & 4 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ module Main where

import Prelude
import Effect (Effect)
import Control.Comonad (extract)
import Data.Maybe (Maybe(..))
import Data.Map (empty, singleton)
import Snabbdom (VNodeProxy, VNodeData, h, patchInitialSelector, text, toVNodeEventObject, toVNodeHookObjectProxy)
import Data.Map (empty)
import Snabbdom (VNodeProxy, VNodeData, h, patchInitialSelector, patch, text, toVNodeEventObject, toVNodeHookObjectProxy)
import RxJS.Observable

type State = Int

emptyVNodeData :: VNodeData
emptyVNodeData =
{ attrs : empty
, on : toVNodeEventObject empty
, hook : toVNodeHookObjectProxy { insert : Nothing, update : Nothing, destroy : Nothing}
, hook : toVNodeHookObjectProxy { insert : Nothing, update : Nothing, destroy : Nothing }
}

initialState :: State
initialState = 10

update :: Observable State
update = interval 1000 # map (\s -> s + 1) # startWith initialState

view :: State -> VNodeProxy
view s = h "div" emptyVNodeData
[ h "strong#msg" emptyVNodeData [text $ "Counter: " <> (show s)]
Expand All @@ -26,4 +31,10 @@ view s = h "div" emptyVNodeData

main :: Effect Unit
main = do
patchInitialSelector "#app" $ view initialState
vnode <- patchInitialSelector "#app" $ view initialState
update # subscribe vnode

subscribe :: VNodeProxy -> Observable State -> Effect Unit
subscribe vnode obs = do
sub <- extract (obs # map view # subscribeNext (patch vnode))
pure unit
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
# yarn lockfile v1


rxjs-compat@^6.3.3:
version "6.3.3"
resolved "https://registry.yarnpkg.com/rxjs-compat/-/rxjs-compat-6.3.3.tgz#2ab3b9ac0dac0c073749d55fef9c03ea1df2045c"

rxjs@^6.3.3:
version "6.3.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.3.tgz#3c6a7fa420e844a81390fb1158a9ec614f4bad55"
dependencies:
tslib "^1.9.0"

snabbdom@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/snabbdom/-/snabbdom-0.7.2.tgz#e9d3930e6374ef8766706ccee4c6ed7b331afa64"

tslib@^1.9.0:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

0 comments on commit 6e8e5b5

Please sign in to comment.