我有一个类,我们称之为LineGraph,它呈现一个折线图.我需要对它进行子类化,但派生类仅在一个地方使用,并且与使用它的类耦合.所以我使用内部类.
我看到两种方法:
匿名内部阶级
public class Gui {
LineGraph graph = new LineGraph() {
// extra functionality here.
};
}
Run Code Online (Sandbox Code Playgroud)
命名内部类
public class Gui {
MyLineGraph graph = new MyLineGraph();
private class MyLineGraph extends LineGraph {
// extra functionality here.
}
}
Run Code Online (Sandbox Code Playgroud)
我不是匿名内部阶级的粉丝,因为坦率地说,我认为它看起来真的很难看.但是在一个仅在一个地方使用的子类的情况下,命名的内部类是否过度杀伤?什么是公认的做法?
我参与了一个包含两个独立存储库的项目,我们很快将它们组合成一个单独的存储库.Lerna的import指挥在这方面会非常有帮助,所以我们将保留项目的历史.
但是,目前在原始存储库中存在一些正在进行的功能分支,当我们转移到monorepo时可能不会准备好.这是我的理解,lerna import只会从源代码库中提取当前已检出的分支 - 这是正确的吗?
所以我想知道是否有办法再次进行导入,但只提取自上次导入后提交的提交?
这样,在功能分支上工作的团队develop一旦准备好就可以合并到分支机构,我们可以将其转移到monorepo中.
或者,是否存在处理此方案的策略?
或者我将不得不等到一切都合并到develop之前lerna import?
谢谢!
我有一个使用Gradle构建的Spring Boot项目.我所有的前端代码都存在src/main/resources/static.这也包括我bower_components,node_modules(对于咕噜任务)等.
现在,我有我的主Gradle构建脚本执行Grunt构建,它连接/缩小我的所有JavaScript,然后它们就会被删除src/main/resources/static/dist.然后,当processResources在Gradle中执行时,整个内容src/main/resources/static/dist将被复制到构建目录中.这对我来说似乎不对 - 应该最终在构建目录中的东西是连接/缩小的JS,CSS,HTML和图像.
我搜索了高低,但没有找到任何明确的方向.以这种方式构建项目是否有最佳实践?
向那里的Swing大师喊出来!!
我已经做了几年的Swing编程,但一直都不清楚这一点.
如您所知,Swing/AWT为您提供了几种在单击按钮时执行特定操作的方法.我已经看到它在我所使用的应用程序中完成了几种不同的方式.我目前正在开展的项目倾向于采用这种方法:
someButton.setActionCommand("mycommand");
someButton.addActionListener(listener);
Run Code Online (Sandbox Code Playgroud)
--snip--
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command.equals("mycommand"))
doThis();
else if (command.equals("someothercommand"))
doThat();
etc.
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎有点笨拙 - 这种编程风格有什么好处,还是使用Swing更好Action?
或者是否存在不同方法更好/更差的不同情况?
我正在尝试将一些 Git 存储库迁移到一个 monorepo 中。
我有两个项目存储库,让我们称它们为project1和project2. 在我的 monorepo 中,我想要一个projects包含两个子目录的目录,project1以及project2. 每个子目录都应包含来自相应项目的文件,并保留 Git 历史记录。
这甚至可以使用标准的 Git 命令吗?
注意:我看过 Lerna -lerna import完全符合我的需要,但不幸的是它只适用于 JS 项目,而我的一个项目是 Ruby 项目。
我有一个Angular CLI项目,我刚刚升级到Angular 6.现在,当我尝试构建我的应用程序时,出现以下错误:
ERROR in ./node_modules/postcss/lib/input.js
Module not found: Error: Can't resolve 'path' in '/Users/jattardi/code/myproject/node_modules/postcss/lib'
ERROR in ./node_modules/postcss/lib/map-generator.js
Module not found: Error: Can't resolve 'path' in '/Users/jattardi/code/myproject/node_modules/postcss/lib'
ERROR in ./node_modules/postcss/lib/previous-map.js
Module not found: Error: Can't resolve 'path' in '/Users/jattardi/code/myproject/node_modules/postcss/lib'
ERROR in ./node_modules/htmlparser2/lib/WritableStream.js
Module not found: Error: Can't resolve 'stream' in '/Users/jattardi/code/myproject/node_modules/htmlparser2/lib'
我糊涂了.首先,我甚至没有使用postcss或htmlparser2直接在我的项目中.所以他们必须是其他东西的依赖.
但是不是path并且stream内置Node模块?怎么可能无法解决它们?
我有一个通知组件,用于在屏幕顶部显示通知。我想让这些通知淡入淡出。的NotificationService具有通知的阵列。添加新通知时setTimeout,会设置一个计时器,通过该计时器将在 5 秒后删除通知。
通知正确显示和消失,但当通知出现时,淡入淡出动画仅适用于:enter过渡。当通知被移除时,它只会消失而没有淡入淡出动画。
知道我做错了什么吗?
notification.component.ts:
animations: [
trigger('fade', [
transition(':enter', [style({ opacity: 0 }), animate('0.2s', style({ opacity: 1 }))]),
transition(':leave', [style({ opacity: 1 }), animate('0.2s', style({ opacity: 0 }))])
])
]
Run Code Online (Sandbox Code Playgroud)
notification.component.html:
<div @fade class="notification notification-{{ notification.theme }}">
<div class="icon"><fa-icon [icon]="icons[notification.theme]"></fa-icon></div>
<div class="message">{{ notification.message }}</div>
<div class="close"><fa-icon (click)="closeButtonClicked()" [icon]="icons.close"></fa-icon></div>
</div>
Run Code Online (Sandbox Code Playgroud)
app.component.html:
<div id="notification-container">
<app-notification *ngFor="let notification of notifications" [notification]="notification"></app-notification>
</div>
Run Code Online (Sandbox Code Playgroud)
app.component.ts:
get notifications() {
return this.notificationService.notifications;
}
Run Code Online (Sandbox Code Playgroud)
notification.service.ts: …
我正在开发一个使用 Markdown 的电子笔记应用程序。目前,我正在致力于将图像插入笔记中(使用 Markdown 语法)。
插入图像时,我的主进程将图像复制到 Notes 目录中,然后返回file:///图像文件的 URL。但是,当我尝试渲染图像时,它无法加载 - 并且出现错误Not allowed to load local resource: file:///Users/joe/notes/images/foo.jpg。
有没有办法配置 Electron 以允许这些本地图像 URL?
我有一个SettingsDialog组件,它具有作为道具传入的初始设置。然后我使用useState最初将当前表单值设置为传入的设置:
export default function SettingsDialog({ settings }) {
const [values, setValues] = useState(settings);
}
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用。该values状态对象始终是一个空的对象。如果我添加两个console.log语句:
export default function SettingsDialog({ settings }) {
const [values, setValues] = useState(settings);
console.log('settings:', settings);
console.log('values:', values);
}
Run Code Online (Sandbox Code Playgroud)
第一个注销正在传入的设置对象,但第二个注销一个空对象。
我是不是不明白useState钩子应该如何工作,或者我只是做错了什么?
我正在开发一个Java Web应用程序,它使用Maven来构建它,并且有很多JavaScript.
我想要做的是基本上在我的JSP文件中有这个:
<c:choose>
<c:when test="PRODUCTION">
<script type="text/javascript" src="/path/to/app.min.js"></script>
</c:when>
<c:otherwise>
<script type="text/javascript" src="/path/to/script1.js"></script>
<script type="text/javascript" src="/path/to/script2.js"></script>
</c:otherwise
</c:choose>
Run Code Online (Sandbox Code Playgroud)
这可能与Maven配置文件有关吗?
我有一个使用ngrx / store的Angular 5项目。该项目由一个应用程序和该应用程序使用的共享库组成。直到今天,我们一直在为两个项目一起编译TypeScript-仅使用TypeScript代码来“发布”该库。
今天,我使用了该库,ng-packagr并使用将该库引入了应用程序yarn link,以便可以运行本地代码。但是,当我尝试启动我的应用程序时,在浏览器中出现此错误:
Unhandled Promise rejection: StaticInjectorError(AppModule)[Store -> StateObservable]:
StaticInjectorError(Platform: core)[Store -> StateObservable]:
NullInjectorError: No provider for StateObservable! ; Zone: <root> ; Task: Promise.then ; Value: Error: StaticInjectorError(AppModule)[Store -> StateObservable]:
StaticInjectorError(Platform: core)[Store -> StateObservable]:
NullInjectorError: No provider for StateObservable!
at _NullInjector.get (core.js:1002)
at resolveToken (core.js:1300)
at tryResolveToken (core.js:1242)
at StaticInjector.get (core.js:1110)
at resolveToken (core.js:1300)
at tryResolveToken (core.js:1242)
at StaticInjector.get (core.js:1110)
at resolveNgModuleDep (core.js:10854)
at _createClass (core.js:10895)
at _createProviderInstance$1 (core.js:10865)
我不知道这是错误的来源。我唯一的提示是它提到了AppModule。在我的中AppModule …
我想在我的Spring应用程序中提供一个服务,该服务使用Java 7 WatchService监视目录中的更改。想法是,当目录中的文件更改时,将通知通过WebSockets连接的客户端。
我如何使bean在其自己的线程中作为服务运行?
java ×3
javascript ×3
typescript ×3
angular ×2
git ×2
spring ×2
angular-cli ×1
architecture ×1
class ×1
electron ×1
gradle ×1
gruntjs ×1
inheritance ×1
jsp ×1
lerna ×1
maven ×1
minify ×1
monorepo ×1
ng-packagr ×1
ngrx ×1
node.js ×1
oop ×1
react-hooks ×1
reactjs ×1
service ×1
swing ×1
webpack ×1
yarnpkg ×1