我正在研究Ruby/React項目。我們使用的是反應的組分和CoffeeScript的和最後的JS由鏈輪組裝:導入深度嵌套的Javascript組件的最佳做法
#= require org/components/whatever
{ Whatever } = Org.Components
這是正常時,沒有太多的嵌套,然後你wrtiting是這樣的:
#= require org/components/whatever
#= require org/components/something/else/whatever
{ Whatever1 } = Org.Components
{ Whatever2 } = Org.Components.Something.Else
今天我試圖找到在哪裏使用Org.Components.Image.Upload
。但有時它被導入爲{ Upload }
或作爲Image.Upload
使用,它不會讓事情變得更容易。
現在我想也許不要再比Org.Components
更進一步。所以如果你需要Image.Upload
- 得到{ Image } = Org.Components
,並使用Image.Upload
。如果變得太長 - 分配給一個變量。
#= require org/components/image
{Image} = Org.Components
Upload = Image.Super.Complex.Upload
# Or use it like this for explicitness
render: ->
Image.Super.Complex.Upload
這裏的最佳做法是什麼?我希望代碼可被搜索。
對象可以幫助減少查找時間,這是什麼,似乎你正在做的,但如果它的組織,該_Dependency宣言Pattern_可以非常有用的局部引用方便。 – ZachPerkitny
我通常在使用深度嵌套對象時使用該方法。 – ZachPerkitny
我不認爲有最佳做法。但是你當然不應該混合它們,使用* * *解構*或*變量賦值。 – Bergi