Skip to content

Commit 622b948

Browse files
committed
Merge pull request #28 from purescript-contrib/topic/remove-st-array
Topic/remove st array
2 parents c158ca2 + 0e1ffc8 commit 622b948

File tree

5 files changed

+26
-102
lines changed

5 files changed

+26
-102
lines changed

MODULE.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -729,21 +729,6 @@
729729
when :: forall e a b. b -> Q -> QEff e (Promise a b)
730730

731731

732-
## Module Angular.ST
733-
734-
### Values
735-
736-
pushAllSTArray :: forall a h r. STArray h a -> [a] -> Eff (st :: ST h | r) Number
737-
738-
pushSTArray :: forall a h r. STArray h a -> a -> Eff (st :: ST h | r) Number
739-
740-
readSTArray :: forall a h r. STArray h a -> Eff (st :: ST h | r) [a]
741-
742-
spliceSTArray :: forall a h r. STArray h a -> Number -> Number -> [a] -> Eff (st :: ST h | r) [a]
743-
744-
writeSTArray :: forall a h r. STArray h a -> [a] -> Eff (st :: ST h | r) [a]
745-
746-
747732
## Module Angular.Scope
748733

749734
### Types

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dist"
1717
],
1818
"dependencies": {
19-
"purescript-arrays": "0.2.2",
19+
"purescript-arrays": "0.3.0",
2020
"purescript-either": "0.1.4",
2121
"purescript-exceptions": "0.2.2",
2222
"purescript-foldable-traversable": "0.1.4",

examples/Todomvc/Controller.purs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import qualified Data.Array as A
44
import qualified Data.String as S
55
import Data.Foldable
66
import Data.Maybe
7+
import Control.Apply ((*>))
78
import Control.Monad (unless, when)
89
import Control.Monad.Eff
9-
import Control.Monad.ST (ST(), STArray(), newSTArray, runSTArray)
1010

1111
import Angular (copy, extend)
1212
import Angular.Location (Location(), getPath, setPath)
1313
import Angular.Scope (Scope(), watch, readScope, extendScope, modifyScope)
14-
import Angular.This(readThis, writeThis)
15-
import Angular.ST (readSTArray, pushSTArray, pushAllSTArray, writeSTArray, spliceSTArray)
14+
import Angular.This (readThis, writeThis)
1615

1716
import Todomvc.Storage (Store(), Todo(), get, put)
1817

@@ -23,33 +22,31 @@ addTodo scope = do
2322
unless empty $ do
2423
let todo = { title: title, completed: false }
2524
todos <- get
26-
put $ todos <> [todo]
27-
pushSTArray s.todos todo
28-
extendScope { newTodo: ""
25+
let res = todos <> [todo]
26+
put res
27+
extendScope { todos: res
28+
, newTodo: ""
2929
, remainingCount: s.remainingCount + 1 } scope
3030

3131
todoCompleted scope todo
3232
= modifyScope (\s -> do
3333
let change = if todo.completed then -1 else 1
34-
arr <- readSTArray s.todos
35-
put arr
34+
put s.todos
3635
return { remainingCount: s.remainingCount + change }
3736
) scope
3837

3938
clearCompletedTodos scope = do
4039
s <- readScope scope
41-
arr <- readSTArray s.todos
42-
let res = A.filter (\a -> not a.completed) arr
40+
let res = A.filter (\a -> not a.completed) s.todos
4341
put res
44-
writeSTArray s.todos res
42+
extendScope { todos: res } scope
4543

4644
markAll scope compl
4745
= modifyScope (\s -> do
48-
arr <- readSTArray s.todos
49-
let res = (\a -> a { completed = not compl }) <$> arr
46+
let res = (\a -> a { completed = not compl }) <$> s.todos
5047
put res
51-
writeSTArray s.todos res
52-
return { remainingCount: if compl then A.length res else 0 }
48+
return { todos: res
49+
, remainingCount: if compl then A.length res else 0 }
5350
) scope
5451

5552
editTodo scope todo = do
@@ -62,31 +59,26 @@ doneEditing scope todo
6259
let title = S.trim todo.title
6360
when (S.length title == 0) $ removeTodo scope todo
6461
extend todo { title: title }
65-
arr <- readSTArray s.todos
66-
put arr
62+
put s.todos
6763
return { editedTodo: Nothing }
6864
) scope
6965

7066
removeTodo scope todo = do
7167
s <- readScope scope
72-
arr <- readSTArray s.todos
73-
let i = A.findIndex (\a -> refEq a todo) arr
74-
unless (i == -1) do
68+
let res = A.filter (\a -> not $ refEq a todo) s.todos
69+
unless (A.length res == A.length s.todos) do
7570
let c = if todo.completed then 0 else -1
76-
extendScope { remainingCount: s.remainingCount + c} scope
77-
spliceSTArray s.todos i 1 []
78-
put arr
71+
extendScope { todos: res
72+
, remainingCount: s.remainingCount + c } scope
73+
put res
7974

8075
revertEditing scope todo = do
8176
s <- readScope scope
82-
arr <- readSTArray s.todos
83-
let i = A.findIndex (\a -> refEq a todo) arr
84-
unless (i == -1) do
77+
let res = A.filter (\a -> not $ refEq a todo) s.todos
78+
unless (A.length res == A.length s.todos) do
8579
case s.originalTodo of
86-
Just t -> do
87-
spliceSTArray s.todos i 1 [t]
88-
doneEditing scope t
89-
return unit
80+
Just t -> extendScope { todos: res <> [t] } scope *>
81+
doneEditing scope t
9082
Nothing -> return unit
9183

9284
watchRemainingCount scope =
@@ -108,15 +100,13 @@ todoctrl scope this location = do
108100
if S.length path == 0 then setPath "/" location else return ""
109101
watchRemainingCount scope
110102
watchLocationPath scope
111-
todosRef <- newSTArray 0 { title: "", completed: false }
112103
todos <- get
113-
pushAllSTArray todosRef todos
114104
let remainingCount = foldl (\b a -> if a.completed then b else b + 1) 0 todos
115105
extendScope { fromMaybe: fromMaybe
116106
, newTodo: ""
117107
, editedTodo: Nothing
118108
, originalTodo: Nothing
119-
, todos: todosRef
109+
, todos: todos
120110
, remainingCount: remainingCount
121111
, location: location
122112
, addTodo: addTodo scope

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "purescript-angular",
33
"private": true,
44
"devDependencies": {
5-
"gulp": "3.8.7",
5+
"gulp": "3.8.10",
66
"gulp-clean": "0.3.1",
77
"gulp-plumber": "0.6.4",
8-
"gulp-purescript": "0.1.1",
8+
"gulp-purescript": "0.1.2",
99
"gulp-util": "3.0.0",
1010
"node-static": "0.7.4"
1111
}

src/Angular/ST.purs

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)