假设我有两个型号
class EntityModel(DB.Model):
id = DB.Column(DB.Unicode(37), primary_key=True)
class DocumentModel(DB.Model):
id = DB.Column(DB.Unicode(37), primary_key=True)
entity_id = DB.Column(DB.Unicode(37), DB.ForeignKey('entity.id', ondelete='cascade'), nullable=True)
entity = DB.relationship('EntityModel')
Run Code Online (Sandbox Code Playgroud)
我可以使用entity_id NULL创建新文档.但是,一旦我将有效的entity_id设置为该文档,我就不能再将其归零.我收到错误:
Cannot add or update a child row: a foreign key constraint fails
如果它具有有效的entity_id,如何在某些文档中将null设置为entity_id?
我试图用试剂项目/试剂·GitHub来开发FormidableLabs/radium ·GitHub,但我已经走到了尽头.
我能够通过这样的"黑客"试剂功能部分地工作create-class(它与原始的几乎相同,我只是添加了js/Radium包装).
(ns myproject.components.radium
(:require [reagent.core :as r]
[reagent.impl.component :as c]
[reagent.impl.util :as util]
[reagent.interop :refer-macros [.' .!]]))
(defn create-class
[body]
(assert (map? body))
(let [
spec (c/cljsify body)
res (js/Radium (.' js/React createClass spec))
;res (.' js/React createClass spec)
f (fn [& args]
(r/as-element (apply vector res args)))]
(util/cache-react-class f res)
(util/cache-react-class res res)
f))
Run Code Online (Sandbox Code Playgroud)
然后我为这样的组件制作了功能
(defn radium []
(create-class
{:reagent-render
(fn []
[:button {:style
[{:backgroundColor "red"
:width 500
:height …Run Code Online (Sandbox Code Playgroud) 我无法使用Heroku Postgres设置Datomic.首先,我成功安装了这个
[com.datomic/datomic-pro "0.9.5206" :exclusions [joda-time]]
Run Code Online (Sandbox Code Playgroud)
我的sql-transactor.properties文件看起来像这样:
protocol=sql
host=localhost
port=4334
license-key=<MY_LICENSE_KEY>
sql-url=jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>
sql-user=<MY_USER>
sql-password=<MY_PASS>
sql-driver-params=ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory
Run Code Online (Sandbox Code Playgroud)
当我尝试从下载的datomic-pro文件夹运行transactor时:
bin/transactor /path/to/folder/sql-transactor.properties
它给出了以下输出:
Launching with Java options -server -Xms1g -Xmx1g -XX:+UseG1GC -XX:MaxGCPauseMillis=50
Starting datomic:sql://<DB-NAME>?jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>?user=<MY_USER>&password=<MY_PASS>&ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory, you may need to change the user and password parameters to work with your jdbc driver ...
System started datomic:sql://<DB-NAME>?jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>?user=<MY_USER>&password=<MY_PASS>&ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory, you may need to change the user and password parameters to work with your jdbc driver
Run Code Online (Sandbox Code Playgroud)
注:该<DB-NAME>输出是字面上<DB-NAME>.这不是我的占位符.我认为这可能是个错误.
现在当我尝试clojure时:
(def uri "datomic:sql://<MY_HEROKU_DB_NAME>?jdbc:postgresql://localhost:5432/<MY_HEROKU_DB_NAME>")
(def conn …Run Code Online (Sandbox Code Playgroud) 我正在尝试扩展库DomKM/silk.
具体来说,有deftype Route哪些实现协议Pattern,它有方法实现,我想在我的自定义Pattern协议实现中重用它.
https://github.com/DomKM/silk/blob/master/src/domkm/silk.cljx#L355
(deftype Route [name pattern]
Pattern
(-match [this -url]
(when-let [params (match pattern (url -url))]
(assoc params ::name name ::pattern pattern)))
(-unmatch [this params]
(->> (dissoc params ::name ::pattern)
(unmatch pattern)
url))
(-match-validator [_]
map?)
(-unmatch-validators [_]
{}))
Run Code Online (Sandbox Code Playgroud)
好的,所以我的实现看起来像这样,但我想"继承" Route的方法.我的意思是首先执行一些自定义逻辑,然后将其传递给原始Route方法.
(deftype MyRoute [name pattern]
silk/Pattern
(-match [this -url]
true) ;match logic here
(-unmatch [this {nm ::name :as params}]
true) ;unmatch logic here
(-match-validator [_] map?)
(-unmatch-validators …Run Code Online (Sandbox Code Playgroud) Lodash _.pluck这样做
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];
_.pluck(users, 'user');
// ? ['barney', 'fred']
Run Code Online (Sandbox Code Playgroud)
好处是它也可以像这样深入:
var users = [
{ 'user': {name: 'barney'}, 'age': 36 },
{ 'user': {name: 'fred'}, 'age': 40 }
];
_.pluck(users, 'user.name');
// ["barney", "fred"]
Run Code Online (Sandbox Code Playgroud)
在 Clojure 核心中是否有等价物?我的意思是,我可以像这样轻松地创建一条线
(defn pluck
[collection path]
(map #(get-in % path) collection))
Run Code Online (Sandbox Code Playgroud)
并像这样使用它:
(def my-coll [{:a {:z 1}} {:a {:z 2}}])
(pluck my-coll [:a :z])
=> (1 2)
Run Code Online (Sandbox Code Playgroud)
我只是想知道 …
所以签名component-will-receive-props是这样的:
https://github.com/reagent-project/reagent/blob/master/src/reagent/core.cljs#L114
:component-will-receive-props (fn [this new-argv])
但是new-args似乎它是函数或js对象。我以为它是道具地图。我如何获得道具地图new-argv?我可以从老去道具this的(reagent/props this),但它的老道具,没有新收到的。
我偶然发现了partial函数的实现cojure.core.它看起来像这样:
(defn partial
"Takes a function f and fewer than the normal arguments to f, and
returns a fn that takes a variable number of additional args. When
called, the returned function calls f with args + additional args."
{:added "1.0"
:static true}
([f] f)
([f arg1]
(fn [& args] (apply f arg1 args)))
([f arg1 arg2]
(fn [& args] (apply f arg1 arg2 args)))
([f arg1 arg2 arg3]
(fn [& args] (apply f arg1 arg2 …Run Code Online (Sandbox Code Playgroud) 首先,这个https://github.com/taylorSando/om-material-ui不适用于最新的React/Material UI.我认为,主要原因是控制台中出现此警告:
Warning: Something is calling a React component directly. Use a factory or JSX instead. See: https://fb.me/react-legacyfactory
我还试图"手动"创建组件:
(ns om-test.core
(:require [om.core :as om :include-macros true]
[om-tools.dom :as dom :include-macros true]
[om-tools.core :refer-macros [defcomponent]]
[om-material-ui.core :as mui :include-macros true]))
(enable-console-print!)
(defonce app-state (atom {:text "Hello Chestnut!"}))
(defn main []
(om/root
(fn [app owner]
(reify
om/IRender
(render [_]
(dom/div (dom/element js/MaterialUI.Paper {} "Hello")
(mui/paper {} "Hello"))
)))
app-state
{:target (. js/document (getElementById "app"))}))
Run Code Online (Sandbox Code Playgroud)
因此,这两种方法都会产生相同的警告.
React显然有一些变化.它建议以编程方式创建组件:
var React = …Run Code Online (Sandbox Code Playgroud) 我的意思是功能,当给定时间返回最小时间单位之前.例如
我想运行npm run build,但我必须增加堆栈大小--stack-size=1500,例如如何将其传递给npm?
通常我会跑node --stack-size=1500 ./some-script.js --some-arg
假设我无法编辑package.json
这与Sending command line argument to npm script不重复,因为那里的答案描述了在这种情况下如何将参数传递给some-script.js,而不是传递给node
假设我有约会日期:
Mon Mar 31 2014 05:42:35 GMT+0200 (CEST)
Wed Sep 02 2015 10:29:38 GMT+0200 (CEST)
和 totalNumberOfDates = 37;
我想获得37个日期的数组(第一个和最后一个日期应该是上面的日期),它们在给定日期之间完全线性分布.
我很欣赏D3.js或moment.js中的优雅解决方案
如何在onMouseDrag事件中实现围绕枢轴旋转组。所以你可以想象我的意思是小提琴,
var point1 = new Point(150, 150);
var point2 = new Point(250, 150);
path.add(point1);
path.add(point2);
var handle1 = new Path.Circle({
center : point1,
radius : 7,
fillColor : 'green'
});
var handle2 = new Path.Circle({
center : point2,
radius : 7,
fillColor : 'blue'
});
var group = new Group(path, handle1, handle2);
group.pivot = point1;
handle1.onMouseDrag = function(event) {
group.position = group.position.subtract(handle1.position).add(event.point);
};
handle2.onMouseDrag = function(event) {
group.rotate(event.point.angle - handle2.position.angle)
};
Run Code Online (Sandbox Code Playgroud)
有一条在边缘有两个手柄的路径。绿色handle1可以正常工作,它应该移动整个路径。蓝色的handle2在拖动时应根据鼠标位置围绕绿色点旋转路径。我在那里的代码可以正常工作,但仅适用于180度低角度的cca。
我在这里想念什么?
非常感谢您的帮助
clojure ×5
javascript ×3
reagent ×2
d3.js ×1
datomic ×1
foreign-keys ×1
lodash ×1
momentjs ×1
node.js ×1
npm ×1
om ×1
paperjs ×1
sql ×1
sqlalchemy ×1