Begin
This commit is contained in:
parent
3bb806c911
commit
990a129c02
8 changed files with 199 additions and 0 deletions
64
.gitignore
vendored
Normal file
64
.gitignore
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# CMake
|
||||
cmake-build-debug/
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
### Dart template
|
||||
# See https://www.dartlang.org/tools/private-files.html
|
||||
|
||||
# Files and directories created by pub
|
||||
.packages
|
||||
.pub/
|
||||
build/
|
||||
# If you're building an application, you may want to check-in your pubspec.lock
|
||||
pubspec.lock
|
||||
|
||||
# Directory created by dartdoc
|
||||
# If you don't generate documentation locally you can remove this line.
|
||||
doc/api/
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/poll.iml" filepath="$PROJECT_DIR$/poll.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
2
analysis_options.yaml
Normal file
2
analysis_options.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
analyzer:
|
||||
strong-mode: true
|
93
lib/angel_poll.dart
Normal file
93
lib/angel_poll.dart
Normal file
|
@ -0,0 +1,93 @@
|
|||
import 'dart:async';
|
||||
import 'package:angel_client/angel_client.dart';
|
||||
|
||||
class Poll extends Service {
|
||||
final Service inner;
|
||||
|
||||
final String idField;
|
||||
final bool asPaginated;
|
||||
|
||||
final List _items = [];
|
||||
final StreamController _onIndexed = new StreamController(),
|
||||
_onRead = new StreamController(),
|
||||
_onCreated = new StreamController(),
|
||||
_onModified = new StreamController(),
|
||||
_onUpdated = new StreamController(),
|
||||
_onRemoved = new StreamController();
|
||||
|
||||
bool Function(dynamic, dynamic) _compare;
|
||||
Timer _timer;
|
||||
|
||||
@override
|
||||
Angel get app => inner.app;
|
||||
|
||||
@override
|
||||
Stream get onIndexed => _onIndexed.stream;
|
||||
|
||||
@override
|
||||
Stream get onRead => _onRead.stream;
|
||||
|
||||
@override
|
||||
Stream get onCreated => _onCreated.stream;
|
||||
|
||||
@override
|
||||
Stream get onModified => _onModified.stream;
|
||||
|
||||
@override
|
||||
Stream get onUpdated => _onUpdated.stream;
|
||||
|
||||
@override
|
||||
Stream get onRemoved => _onRemoved.stream;
|
||||
|
||||
Poll(this.inner, Duration interval,
|
||||
{this.idField: 'id', this.asPaginated: false, bool compare(a, b)}) {
|
||||
_timer = new Timer.periodic(interval, _timerCallback);
|
||||
_compare = compare ?? (a, b) => a[idField ?? 'id'] == b[idField ?? 'id'];
|
||||
}
|
||||
|
||||
@override
|
||||
Future close() async {
|
||||
_timer.cancel();
|
||||
_onIndexed.close();
|
||||
_onRead.close();
|
||||
_onCreated.close();
|
||||
_onModified.close();
|
||||
_onUpdated.close();
|
||||
_onRemoved.close();
|
||||
}
|
||||
|
||||
@override
|
||||
Future index([Map params]) {
|
||||
return inner.index().then((data) {
|
||||
var items = asPaginated == true ? data['data'] : data;
|
||||
_items
|
||||
..clear()
|
||||
..addAll(items);
|
||||
_onIndexed.add(items);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future remove(id, [Map params]) {}
|
||||
|
||||
@override
|
||||
Future update(id, data, [Map params]) {}
|
||||
|
||||
@override
|
||||
Future modify(id, data, [Map params]) {}
|
||||
|
||||
@override
|
||||
Future create(data, [Map params]) {}
|
||||
|
||||
@override
|
||||
Future read(id, [Map params]) {}
|
||||
|
||||
void _timerCallback(Timer timer) {
|
||||
index().then((data) {
|
||||
var items = asPaginated == true ? data['data'] : data;
|
||||
|
||||
// TODO: Check create, modify, remove
|
||||
|
||||
}).catchError(_onIndexed.addError);
|
||||
}
|
||||
}
|
14
poll.iml
Normal file
14
poll.iml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
</component>
|
||||
</module>
|
6
pubspec.yaml
Normal file
6
pubspec.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
name: angel_poll
|
||||
dependencies:
|
||||
angel_client: ^1.0.0
|
||||
dev_dependencies:
|
||||
angel_test: ^1.1.0
|
||||
test: ^0.12.0
|
Loading…
Reference in a new issue