Skip to content

Instantly share code, notes, and snippets.

(defmulti mutate om/dispatch)
(defmethod mutate 'element/drag
[{:keys [state]} _ params]
{:value {:keys [:elements/dragged]}
:action (fn []
(if-not (empty? params)
(swap! state assoc :elements/dragged params)
(swap! state assoc :elements/dragged nil)))})
(defui App
static om/IQuery
(query [this]
[{:app/lists (om/get-query ElementList)}
:elements/dragged])
Object
(render [this]
(let [{:keys [app/lists elements/dragged]} (om/props this)]
(dom/div nil
(dom/h1 nil "Lists with draggable behavior !")
(defui ElementList
static om/Ident
(ident [this {:keys [id]}]
[:list/by-id id])
static om/IQuery
(query [this]
[:id {:elements (om/get-query Element)}])
Object
(render [this]
(let [{:keys [id elements]} (om/props this)]
(defui Element
static om/Ident
(ident [this {:keys [id]}]
[:element/by-id id])
static om/IQuery
(query [this]
[:id :text])
Object
(render [this]
(let [{:keys [id text]} (om/props this)]
;; REPL
(om/tree->db App init-data true)
{:app/lists [[:list/by-id 1] [:list/by-id 2] [:list/by-id 3]],
:element/by-id {1 {:id 1, :text "This is a draggable element 1"},
2 {:id 2, :text "This is a draggable element 2"},
3 {:id 3, :text "This is a draggable element 3"},
4 {:id 4, :text "This is a draggable element 4"},
5 {:id 5, :text "This is a draggable element 5"},
6 {:id 6, :text "This is a draggable element 6"},
@dupuchba
dupuchba / step0.cljs
Created March 16, 2017 15:42
Gist used to make HTML Elements draggable with om.next in Clojurescript
;; =============================================================================
;; Initial Data
(def init-data {:app/lists [{:id 1
:elements [{:id 1
:text "This is a draggable element 1"}
{:id 2
:text "This is a draggable element 2"}
{:id 3
:text "This is a draggable element 3"}
{:id 4
(def init-data {:app/lists [{:id 1
:elements [{:id 1
:text "This is a draggable element 1"}
{:id 2
:text "This is a draggable element 2"}
{:id 3
:text "This is a draggable element 3"}
{:id 4
:text "This is a draggable element 4"}
{:id 5
@dupuchba
dupuchba / row.js
Last active December 28, 2015 18:18
Filter to be used with Twitter Bootstrap col-md's and row's. Can be optimized greatly but still work well
'use strict';
angular.module('dailymotionApp')
.filter('col', function(){
return function(input, numColumns){
if(input !== undefined) {
var filtered = [];
for(var x = 0; x < input.length; x++){
if(x % numColumns === 0){
filtered.push(filtered.length);
@dupuchba
dupuchba / gitlivelog.sh
Created October 17, 2012 06:49 — forked from xero/gitlivelog.sh
git graph live log
#!/bin/sh
while true;
do
clear
git log \
--graph \
--all \
--color \
--date=short \
-10 \
@dupuchba
dupuchba / README.markdown
Created May 24, 2012 20:05 — forked from Yavari/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
 # this function receives the typeahead object and the query string