From 73b85e787dcf750cd9be6888671fe09972cc2704 Mon Sep 17 00:00:00 2001 From: Ritesh Pahwa <35204975+RADKick@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:43:12 -0400 Subject: [PATCH 1/3] jskick example Example todomvc with jskick --- examples/jskick/index.html | 46 +++++++++++++ examples/jskick/index.js | 130 +++++++++++++++++++++++++++++++++++ examples/jskick/package.json | 12 ++++ examples/jskick/readme.md | 36 ++++++++++ examples/jskick/style.css | 3 + 5 files changed, 227 insertions(+) create mode 100644 examples/jskick/index.html create mode 100644 examples/jskick/index.js create mode 100644 examples/jskick/package.json create mode 100644 examples/jskick/readme.md create mode 100644 examples/jskick/style.css diff --git a/examples/jskick/index.html b/examples/jskick/index.html new file mode 100644 index 0000000000..c488aa4649 --- /dev/null +++ b/examples/jskick/index.html @@ -0,0 +1,46 @@ +
+
+

todos

+ +
+
+ + + +
+ +
+ \ No newline at end of file diff --git a/examples/jskick/index.js b/examples/jskick/index.js new file mode 100644 index 0000000000..ab52c6887d --- /dev/null +++ b/examples/jskick/index.js @@ -0,0 +1,130 @@ +// Import stylesheets +import "todomvc-common/base.css"; +import "todomvc-app-css/index.css"; +import "./style.css"; +import kick from "jskick"; + +var vm = { + current: "", + todos: [], + filteredTodos: [], + hasTodos: false, + allCompleted: false, + remainingCount: 0, + completedCount: 0, + showFooter: false, + mode: "all", + showMode(mode) { + return mode === vm.mode; + }, + setMode(mode) { + vm.mode = mode; + vm.filter(); + return false; + }, + count() { + vm.filter(); + return vm.remainingCount; + }, + add() { + if (vm.current.length) { + vm.todos.push({ + title: vm.current, + completed: false + }); + vm.current = ""; + vm.filter(); + vm.hasTodos = vm.todos.length > 0; + } + }, + editItem(todo) { + vm.oldTitle = todo.title; + todo.editing = true; + }, + saveEditing(todo) { + todo.editing = false; + }, + cancelEditing(todo) { + todo.title = vm.oldTitle; + todo.editing = false; + }, + remove(todo) { + let idx = vm.todos.indexOf(todo); + if (idx > -1) { + vm.todos.splice(idx, 1); + } + vm.hasTodos = vm.todos.length > 0; + vm.filter(); + }, + filter(todo) { + vm.filteredTodos = vm.todos.filter(x => { + switch (vm.mode) { + case "active": + return !x.completed; + case "completed": + return x.completed; + default: + return true; + } + }); + vm.completedCount = vm.todos.filter(x => x.completed).length; + vm.remainingCount = vm.todos.length - vm.completedCount; + + vm.showFooter = vm.completedCount > 0 || vm.remainingCount > 0; + }, + removeCompleted() { + vm.todos = vm.todos.filter(x => !x.completed); + vm.filter(); + }, + markCompleted() { + if (vm.allCompleted) { + vm.todos.forEach(x => { + x.completed = true; + }); + vm.filter(); + vm.allCompleted = false; + } + }, + getLabel(count) { + return count === 1 ? "item" : "items"; + } +}; + +kick.keyUpBinder = function(key) { + kick.binders["^#" + key.toLowerCase()] = { + bind: function(el) { + var view = this; + view.keyEvHandler = + view.keyEvHandler || + (ev => { + if (ev.key === key) { + let processedArgs = view.parseFormatterArguments( + view.fnArgs, + 0, + null, + view.view.models + ); + let handler = view.observer.value(); + handler && handler.apply(view, processedArgs); + } + }); + if (!view.keyEv) { + view.keyEv = el.addEventListener("keyup", event => + view.keyEvHandler(event) + ); + } + }, + unbind: function(el) { + this.keyEv && el.removeEventListener("keyup", this.keyEv); + }, + function: true + }; +}; + +const ENTER_KEY = "Enter"; +const ESCAPE_KEY = "Escape"; +kick.keyUpBinder(ENTER_KEY); +kick.keyUpBinder(ESCAPE_KEY); + +// you may say '[kick-app] or '#kickApp' or 'body' or ... +kick.bind("", vm); diff --git a/examples/jskick/package.json b/examples/jskick/package.json new file mode 100644 index 0000000000..4d22ad7e90 --- /dev/null +++ b/examples/jskick/package.json @@ -0,0 +1,12 @@ +{ + "name": "js-r5mnzv", + "version": "0.0.0", + "private": true, + "dependencies": { + "jskick": "^0.9.92", + "director": "^1.2.8", + "jquery": "^3.3.1", + "todomvc-app-css": "^2.1.2", + "todomvc-common": "^1.0.5" + } +} \ No newline at end of file diff --git a/examples/jskick/readme.md b/examples/jskick/readme.md new file mode 100644 index 0000000000..4ba91736fa --- /dev/null +++ b/examples/jskick/readme.md @@ -0,0 +1,36 @@ +# jskick TodoMVC Example + +> jskick helps you simplify dynamic JavaScript UIs using the Model-View-ViewModel (MVVM) pattern. + +> _[jskick - jskick.dev](http://jskick.dev)_ + + +## Learning jskick + +The [jskick website](http://jskick.dev) is a great resource for getting started. + +Here are some links you may find helpful: + +* [Documentation](http://jskick.dev/docs/) +* [Tutorials](http://jskick.dev/learn) +* [Live examples](http://jskick.dev/examples) + +Articles and guides from the community: + +* [Getting Started with jskick]() +* [Into the Ring with jskick]() +* [Beginners Guide to jskick]() + +Get help from other jskick users: + +* [jskick on StackOverflow](http://stackoverflow.com/questions/tagged/jskick) +* [Mailing list on Google Groups](http://groups.google.com/group/jskick) +* [jskick on Twitter](http://twitter.com/jskick) + + +_If you have other helpful links to share, or find any of the links above no longer work, please [let us know](https://github.com/tastejs/todomvc/issues)._ + + +## Credit + +This TodoMVC application was originally created by [Ritesh](https://github.com/radkick/jskick-todomvc) \ No newline at end of file diff --git a/examples/jskick/style.css b/examples/jskick/style.css new file mode 100644 index 0000000000..38317a797e --- /dev/null +++ b/examples/jskick/style.css @@ -0,0 +1,3 @@ +h1, h2 { + font-family: Lato; +} \ No newline at end of file From 7bd1a0b87cca647c85c240e8f40ae8d4749b06dc Mon Sep 17 00:00:00 2001 From: Ritesh Pahwa <35204975+RADKick@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:46:59 -0400 Subject: [PATCH 2/3] Modifed readme --- examples/jskick/readme.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/jskick/readme.md b/examples/jskick/readme.md index 4ba91736fa..90c2a21682 100644 --- a/examples/jskick/readme.md +++ b/examples/jskick/readme.md @@ -4,6 +4,7 @@ > _[jskick - jskick.dev](http://jskick.dev)_ +Run/modify example of jskick ToDo MVC at [Stackblitz](https://stackblitz.com/edit/jskick-todo?file=index.html) ## Learning jskick @@ -11,21 +12,19 @@ The [jskick website](http://jskick.dev) is a great resource for getting started. Here are some links you may find helpful: -* [Documentation](http://jskick.dev/docs/) -* [Tutorials](http://jskick.dev/learn) -* [Live examples](http://jskick.dev/examples) +* [Github](https://github.com/RADKick/jskick) +* [Documentation](http://jskick.dev/docs/) Coming soon +* [Tutorials](http://jskick.dev/learn) Coming soon +* [Live examples](http://jskick.dev/examples) Coming soon Articles and guides from the community: * [Getting Started with jskick]() -* [Into the Ring with jskick]() * [Beginners Guide to jskick]() Get help from other jskick users: * [jskick on StackOverflow](http://stackoverflow.com/questions/tagged/jskick) -* [Mailing list on Google Groups](http://groups.google.com/group/jskick) -* [jskick on Twitter](http://twitter.com/jskick) _If you have other helpful links to share, or find any of the links above no longer work, please [let us know](https://github.com/tastejs/todomvc/issues)._ @@ -33,4 +32,4 @@ _If you have other helpful links to share, or find any of the links above no lon ## Credit -This TodoMVC application was originally created by [Ritesh](https://github.com/radkick/jskick-todomvc) \ No newline at end of file +This TodoMVC application was originally created by [Ritesh](https://github.com/radkick/jskick-todomvc) From 525b62bd00ccb15edf66f6aab53afc9d69b7173f Mon Sep 17 00:00:00 2001 From: Ritesh Pahwa <35204975+RADKick@users.noreply.github.com> Date: Mon, 27 Apr 2020 16:09:23 -0400 Subject: [PATCH 3/3] Updated the repo link --- examples/jskick/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/jskick/index.html b/examples/jskick/index.html index c488aa4649..e4b7fa9121 100644 --- a/examples/jskick/index.html +++ b/examples/jskick/index.html @@ -41,6 +41,6 @@

todos

\ No newline at end of file +