From 6e8f8f03d1a5c898ec167731674bf55ac5a2c0f4 Mon Sep 17 00:00:00 2001 From: talhaahsan Date: Fri, 13 Apr 2018 11:56:46 -0500 Subject: [PATCH 1/3] Commit Message :wt --- elm-todo/Todo.elm | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/elm-todo/Todo.elm b/elm-todo/Todo.elm index 3a07b24..ab8a0fd 100755 --- a/elm-todo/Todo.elm +++ b/elm-todo/Todo.elm @@ -45,7 +45,6 @@ type alias Model = type alias Entry = { description : String , completed : Bool - , editing : Bool , id : Int } @@ -62,7 +61,6 @@ newEntry : String -> Int -> Entry newEntry desc id = { description = desc , completed = False - , editing = False , id = id } @@ -76,8 +74,6 @@ to them. -} type Msg = UpdateNewEntryField String - | EditingEntry Int Bool - | UpdateEntry Int String | Add | Delete Int | DeleteAllCompleted @@ -102,29 +98,6 @@ update msg model = UpdateNewEntryField str -> { model | newEntryField = str } - EditingEntry id isEditing -> - let - updateEntry t = - if t.id == id then - { t | editing = isEditing } - else - t - - focus = - Dom.focus ("todo-" ++ toString id) - in - { model | entries = List.map updateEntry model.entries } - - UpdateEntry id task -> - let - updateEntry t = - if t.id == id then - { t | description = task } - else - t - in - { model | entries = List.map updateEntry model.entries } - Check id isCompleted -> let updateEntry t = @@ -229,7 +202,7 @@ viewKeyedEntry todo = viewEntry : Entry -> Html Msg viewEntry todo = li - [ classList [ ( "completed", todo.completed ), ( "editing", todo.editing ) ] ] + [ classList [ ( "completed", todo.completed ) ] ] [ div [ class "view" ] [ input @@ -239,8 +212,7 @@ viewEntry todo = , onClick (Check todo.id (not todo.completed)) ] [] - , label - [ onDoubleClick (EditingEntry todo.id True) ] + , label [] [ text todo.description ] , button [ class "destroy" @@ -253,9 +225,6 @@ viewEntry todo = , value todo.description , name "title" , id ("todo-" ++ toString todo.id) - , onInput (UpdateEntry todo.id) - , onBlur (EditingEntry todo.id False) - , onEnter (EditingEntry todo.id False) ] [] ] From 35e8a16e23ed48fb838dfc90c9022446bb13ad50 Mon Sep 17 00:00:00 2001 From: talhaahsan Date: Fri, 13 Apr 2018 11:57:59 -0500 Subject: [PATCH 2/3] Git commit for Ruby and Elm Portions. They should be done barring a major snafu --- ruby-todo/lib/engine.rb | 5 +++-- ruby-todo/lib/messages.rb | 38 +++++++++++++++++++++++++++---------- ruby-todo/lib/model.rb | 4 ++-- ruby-todo/test/todo_test.rb | 2 +- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/ruby-todo/lib/engine.rb b/ruby-todo/lib/engine.rb index a257c20..0c77cf6 100644 --- a/ruby-todo/lib/engine.rb +++ b/ruby-todo/lib/engine.rb @@ -4,9 +4,10 @@ def self.run(*args) end def self.run_with_history(model, messages) + # Messages are things like update, add, delete, check, delete all completed etc + # But model is composed of previous entries, an empty entry, and the next entry ID. While entires are ID, Description, Checked messages.map do |msg| - msg.apply_to(model) - model + model = msg.apply_to(model) end end end diff --git a/ruby-todo/lib/messages.rb b/ruby-todo/lib/messages.rb index abe85de..7447b38 100644 --- a/ruby-todo/lib/messages.rb +++ b/ruby-todo/lib/messages.rb @@ -2,13 +2,14 @@ module Msg class Add def apply_to(model) + new_entries = model.entries.dup unless model.new_entry_field.blank? - model.entries << Entry.new( - description: model.new_entry_field, - id: model.next_id) + new_entries << Entry.new(description: model.new_entry_field, id: model.next_id) end - model.next_id += 1 - model.new_entry_field = "" + next_id = model.next_id.dup #even need the dup? + next_id += 1 + new_model = Model.new(entries: new_entries, new_entry_field: "", next_id: next_id) + return new_model end end @@ -20,7 +21,11 @@ def initialize(str) attr_reader :str def apply_to(model) - model.new_entry_field = str + new_entry_field = str + entries = model.entries + next_id = model.next_id + new_model = Model.new(entries: entries, new_entry_field: new_entry_field, next_id: next_id) + return new_model end end @@ -32,11 +37,18 @@ def initialize(id, is_completed) attr_reader :id, :is_completed def apply_to(model) - model.entries.each do |entry| + entries = model.entries.dup + new_entries = [] + entries.each do |entry| + is_completed_val = entry.completed if entry.id == id - entry.completed = is_completed + is_completed_val = is_completed end + new_entry = Entry.new(id: entry.id, description: entry.description, completed: is_completed_val) + new_entries << new_entry end + new_model = Model.new(entries: new_entries, new_entry_field: model.new_entry_field, next_id: model.next_id) + return new_model end end @@ -48,13 +60,19 @@ def initialize(id) attr_reader :id def apply_to(model) - model.entries.reject! { |e| e.id == id } + entries = model.entries.dup + entries.reject! { |e| e.id == id } + new_model = Model.new(entries: entries, new_entry_field: model.new_entry_field, next_id: model.next_id) + return new_model end end class DeleteAllCompleted def apply_to(model) - model.entries.reject!(&:completed) + entries = model.entries.dup + entries.reject!(&:completed) + new_model = Model.new(entries: entries, new_entry_field: model.new_entry_field, next_id: model.next_id) + return new_model end end diff --git a/ruby-todo/lib/model.rb b/ruby-todo/lib/model.rb index 75a6085..e64ca6a 100644 --- a/ruby-todo/lib/model.rb +++ b/ruby-todo/lib/model.rb @@ -5,7 +5,7 @@ def initialize(entries: [], new_entry_field: "", next_id: nil) (entries.lazy.map(&:id).max || -1) + 1 end - attr_accessor :entries, :new_entry_field, :next_id + attr_reader :entries, :new_entry_field, :next_id def ==(other) !other.nil? && @@ -20,7 +20,7 @@ def initialize(id:, description:, completed: false) @description, @id, @completed = description, id, completed end - attr_accessor :description, :completed, :id + attr_reader :description, :completed, :id def ==(other) !other.nil? && diff --git a/ruby-todo/test/todo_test.rb b/ruby-todo/test/todo_test.rb index f7436c7..9f07d6e 100644 --- a/ruby-todo/test/todo_test.rb +++ b/ruby-todo/test/todo_test.rb @@ -91,7 +91,7 @@ end it "supports time travel" do - skip "Mutable model does not support time travel" + "Mutable model does not support time travel" actual_history = Engine.run_with_history(Model.new, [ Msg::UpdateNewEntryField.new("go forward in time"), From bb54a52d84281f11445628fe4ad8e1b4f5e34596 Mon Sep 17 00:00:00 2001 From: talhaahsan Date: Fri, 13 Apr 2018 19:31:01 -0500 Subject: [PATCH 3/3] Comitting everything for this project. Swift should be done now. --- .DS_Store | Bin 0 -> 6148 bytes elm-todo/Todo.elm | 3 +- ruby-todo/.DS_Store | Bin 0 -> 6148 bytes ruby-todo/.idea/.rakeTasks | 7 + .../inspectionProfiles/Project_Default.xml | 6 + ruby-todo/.idea/misc.xml | 4 + ruby-todo/.idea/modules.xml | 8 + ruby-todo/.idea/ruby-todo.iml | 18 + ruby-todo/.idea/workspace.xml | 430 ++++++++++++++++++ swift-todo/Sources/Todo/Engine.swift | 16 +- swift-todo/Sources/Todo/Message.swift | 34 +- swift-todo/Sources/Todo/Model.swift | 4 +- swift-todo/Tests/TodoTests/TodoTests.swift | 3 +- 13 files changed, 512 insertions(+), 21 deletions(-) create mode 100644 .DS_Store create mode 100644 ruby-todo/.DS_Store create mode 100644 ruby-todo/.idea/.rakeTasks create mode 100644 ruby-todo/.idea/inspectionProfiles/Project_Default.xml create mode 100644 ruby-todo/.idea/misc.xml create mode 100644 ruby-todo/.idea/modules.xml create mode 100644 ruby-todo/.idea/ruby-todo.iml create mode 100644 ruby-todo/.idea/workspace.xml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a8aae6f4666d306842fc3bc3b5495a1fd586c196 GIT binary patch literal 6148 zcmeHK&2H2%5FWP+b%GFkKx&V^AaU5DT?w?H3MnkxLl2cIg4zS1HX#d*l*ZL2OVlol za^WH14f-fNK_3TZ?4jE3kGLUJJkt0Z&yN#-a_krYL~oRI0Ga?GQ3)G9HVcH}q;s;u z9tsLGMhO}c&^wuaKbP$sjseHOzs7+5xCfBI32egD_Zw$A#+RjyVGH%)Pb22_CCuc< zRdLGsKjPCYEy{NLQmm{tZrxs!(wF{S|6O>jtFVm9QPGQrZ>YBymB%sLueHvu>?qz( z2i0No{!5*gQJN2irZ`OonDX`@%@bYq^e9gXGfrp&QhL%mY;KIl-EOy~I^Cy}mO{JT zQjecJn@l{p{-E=G=ji0@eEfOx<(rub2;8`g+++L=-_e+x=%;X)XFC6gF{<<66>P%` z=)*4JBcw2)t#69D3(T6P&VwP0AcnJLWQ+AbSKL&(7mzbUxDN$XkirLCsY_O?_&P%% zcAYF_fS10!voPwMjseHO|I7gG4+@nqV5}{gtpgi#1wd?|+X&k9%Rn`XF<`7MVgyCl zQbb!S_=+KHIrk8tj^YheBN$U;AO?)J SMf9M!9|1#yYa9cAm4RR8dCjK) literal 0 HcmV?d00001 diff --git a/elm-todo/Todo.elm b/elm-todo/Todo.elm index ab8a0fd..117a56e 100755 --- a/elm-todo/Todo.elm +++ b/elm-todo/Todo.elm @@ -282,8 +282,7 @@ viewControlsClear entriesCompleted = infoFooter : Html msg infoFooter = footer [ class "info" ] - [ p [] [ text "Double-click to edit a todo" ] - , p [] + [ p [] [ text "Written by " , a [ href "https://github.com/evancz" ] [ text "Evan Czaplicki" ] ] diff --git a/ruby-todo/.DS_Store b/ruby-todo/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f2782398c4c831a6018115e3634f8696a29ed1ed GIT binary patch literal 6148 zcmeHK!EVz)5S>i|*#r}yuD znI=%^ITA`K-b>YCl&-N|;%`)d*RDxVDW(&8M_1NQMHu17Vheunhc-k+H<#ITA8W4Y zkdDo|FY3Om)YZXDC|YKTjcQgj%}=9L&-FDrO_RLn^}dN(y>ab&Q_8k%-)g@Nj?^?L z!eWvS!|`kGJqwGY$i^>}N*8e$y-ecie&^1%%8D?_;;}AHMlmRFUM1N`O^0fdjdDFt zUNhnSDpth&zQRM-nNz?i;1sA* zz<#LYjjBPHa|$>G{%ZyJ`{2PDeT$_*{pmoXj{v|1(%KO7Pb1fO7JZAQL5#qJDFvER zVUHNXlq2t1o^P=d~k!8J~SKdQh_FTaib literal 0 HcmV?d00001 diff --git a/ruby-todo/.idea/.rakeTasks b/ruby-todo/.idea/.rakeTasks new file mode 100644 index 0000000..54e8039 --- /dev/null +++ b/ruby-todo/.idea/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/ruby-todo/.idea/inspectionProfiles/Project_Default.xml b/ruby-todo/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..b0db9b0 --- /dev/null +++ b/ruby-todo/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ruby-todo/.idea/misc.xml b/ruby-todo/.idea/misc.xml new file mode 100644 index 0000000..42cb086 --- /dev/null +++ b/ruby-todo/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ruby-todo/.idea/modules.xml b/ruby-todo/.idea/modules.xml new file mode 100644 index 0000000..f6178b4 --- /dev/null +++ b/ruby-todo/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ruby-todo/.idea/ruby-todo.iml b/ruby-todo/.idea/ruby-todo.iml new file mode 100644 index 0000000..6d597c0 --- /dev/null +++ b/ruby-todo/.idea/ruby-todo.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ruby-todo/.idea/workspace.xml b/ruby-todo/.idea/workspace.xml new file mode 100644 index 0000000..369bff1 --- /dev/null +++ b/ruby-todo/.idea/workspace.xml @@ -0,0 +1,430 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + skip + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +