Skip to content

Commit 95bfff4

Browse files
committed
Querys and references are immutable, allowing for off() to work for references with modifiers
Everytime you add a modifier (e.g. limitToLast) or change the reference (e.g. child()), you make a new immutable reference/query. This is necessary so that when it comes time to .off()ing your listeners, you can call off on the exact reference/query that you subscribed to. Note that two references or two querys with the same information are NOT the same. This *could* be changed in the future to better align with firebase. let base = firestack.reference('/messages'); base.on('child_added', this.onChildAdded); base.on('child_changed', this.onChildChanged); let newMessages = base.startAt('1'); newMessages.on('child_added', this.onNewMessagesAdded); newMessages.off('child_added', this.onNewMessagesAdded); let latestMessage1 = base.limitToLast(1); latestMessage1.on('child_added', this.onLastMessage1); latestMessage1.off('child_added', this.onLastMessage1); let latestMessage2 = base.limitToLast(1); // *NOT* the same as latestMessage1 latestMessage2.on('child_added', this.onLastMessage2); latestMessage2.off('child_added', this.onLastMessage2); base.off('child_added', this.onChildAdded); base.off('child_changed', this.onChildChanged);
1 parent e845c29 commit 95bfff4

9 files changed

+627
-395
lines changed

.babelrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": ["react-native"]
3-
}
2+
"presets": ["react-native"],
3+
"plugins": ["transform-flow-strip-types"]
4+
}

lib/.flowconfig

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
[ignore]
2+
3+
4+
# Some modules have their own node_modules with overlap
5+
.*/node_modules/node-haste/.*
6+
7+
8+
# React Native problems
9+
.*/node_modules/react-native/Libraries/Animated/src/AnimatedInterpolation.js
10+
.*/node_modules/react-native/Libraries/Animated/src/Interpolation.js
11+
.*/node_modules/react-native/Libraries/BugReporting/dumpReactTree.js
12+
.*/node_modules/react-native/Libraries/CustomComponents/NavigationExperimental/NavigationHeader.js
13+
.*/node_modules/react-native/Libraries/CustomComponents/NavigationExperimental/NavigationPagerStyleInterpolater.js
14+
.*/node_modules/react-native/Libraries/Experimental/WindowedListView.js
15+
.*/node_modules/react-native/Libraries/Image/Image.io.js
16+
.*/node_modules/react-native/Libraries/NavigationExperimental/NavigationExperimental.js
17+
.*/node_modules/react-native/Libraries/NavigationExperimental/NavigationHeaderStyleInterpolator.js
18+
.*/node_modules/react-native/Libraries/Network/FormData.js
19+
.*/node_modules/react-native/Libraries/ReactIOS/YellowBox.js
20+
21+
22+
23+
# Ignore react and fbjs where there are overlaps, but don't ignore
24+
# anything that react-native relies on
25+
.*/node_modules/fbjs/lib/Map.js
26+
.*/node_modules/fbjs/lib/ErrorUtils.js
27+
28+
# Flow has a built-in definition for the 'react' module which we prefer to use
29+
# over the currently-untyped source
30+
.*/node_modules/react/react.js
31+
.*/node_modules/react/lib/React.js
32+
.*/node_modules/react/lib/ReactDOM.js
33+
34+
.*/__mocks__/.*
35+
.*/__tests__/.*
36+
37+
.*/commoner/test/source/widget/share.js
38+
39+
# Ignore commoner tests
40+
.*/node_modules/commoner/test/.*
41+
42+
# See https://github.com/facebook/flow/issues/442
43+
.*/react-tools/node_modules/commoner/lib/reader.js
44+
45+
# Ignore jest
46+
.*/node_modules/jest-cli/.*
47+
48+
# Ignore Website
49+
.*/website/.*
50+
51+
# Ignore generators
52+
.*/local-cli/generator.*
53+
54+
# Ignore BUCK generated folders
55+
.*\.buckd/
56+
57+
.*/node_modules/is-my-json-valid/test/.*\.json
58+
.*/node_modules/iconv-lite/encodings/tables/.*\.json
59+
.*/node_modules/y18n/test/.*\.json
60+
.*/node_modules/spdx-license-ids/spdx-license-ids.json
61+
.*/node_modules/spdx-exceptions/index.json
62+
.*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json
63+
.*/node_modules/resolve/lib/core.json
64+
.*/node_modules/jsonparse/samplejson/.*\.json
65+
.*/node_modules/json5/test/.*\.json
66+
.*/node_modules/ua-parser-js/test/.*\.json
67+
.*/node_modules/builtin-modules/builtin-modules.json
68+
.*/node_modules/binary-extensions/binary-extensions.json
69+
.*/node_modules/url-regex/tlds.json
70+
.*/node_modules/joi/.*\.json
71+
.*/node_modules/isemail/.*\.json
72+
.*/node_modules/tr46/.*\.json
73+
.*/node_modules/protobufjs/src/bower.json
74+
.*/node_modules/grpc/node_modules/protobufjs/src/bower.json
75+
76+
[include]
77+
node_modules/fbjs/lib
78+
79+
[libs]
80+
js/flow-lib.js
81+
node_modules/react-native/Libraries/react-native/react-native-interface.js
82+
node_modules/react-native/flow
83+
node_modules/fbjs/flow/lib
84+
85+
[options]
86+
module.system=haste
87+
88+
experimental.strict_type_args=true
89+
unsafe.enable_getters_and_setters=true
90+
91+
esproposal.class_static_fields=enable
92+
esproposal.class_instance_fields=enable
93+
94+
munge_underscores=true
95+
96+
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
97+
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
98+
99+
suppress_type=$FlowIssue
100+
suppress_type=$FlowFixMe
101+
suppress_type=$FixMe
102+
103+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
104+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
105+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy

lib/firestack.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* @providesModule Firestack
3-
* @flow
43
*/
54
import Log from './utils/log'
65

@@ -21,7 +20,7 @@ import Singleton from './utils/singleton'
2120

2221
import RemoteConfig from './modules/remoteConfig'
2322
import {Authentication} from './modules/authentication'
24-
import {Database} from './modules/database'
23+
import {Database} from './modules/database.js'
2524
import {Analytics} from './modules/analytics'
2625
import {Storage} from './modules/storage'
2726
import {Presence} from './modules/presence'
@@ -38,7 +37,6 @@ export class Firestack extends Singleton {
3837

3938
Log.enable(instance._debug);
4039
log = instance._log = new Log('firestack');
41-
4240
log.info('Creating new firestack instance');
4341

4442
instance._remoteConfig = instance.options.remoteConfig || {};

lib/modules/base.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/**
2-
* @flow
32
*/
43
import Log from '../utils/log'
54

@@ -110,4 +109,4 @@ export class ReferenceBase extends Base {
110109
}
111110
return pathStr;
112111
}
113-
}
112+
}

0 commit comments

Comments
 (0)