flux_on_rails 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/flux_on_rails-1.0.0.gem +0 -0
- data/flux_on_rails.gemspec +23 -0
- data/lib/flux_on_rails.rb +5 -0
- data/lib/flux_on_rails/version.rb +3 -0
- data/lib/generators/flux_on_rails/install_generator.rb +51 -0
- data/lib/generators/flux_on_rails/templates/actions/example-actions.js +22 -0
- data/lib/generators/flux_on_rails/templates/application.js +3 -0
- data/lib/generators/flux_on_rails/templates/components/.gitkeep +0 -0
- data/lib/generators/flux_on_rails/templates/constants/app-constants.js +5 -0
- data/lib/generators/flux_on_rails/templates/dispatcher.js +280 -0
- data/lib/generators/flux_on_rails/templates/dispatchers/app-dispatcher.js +29 -0
- data/lib/generators/flux_on_rails/templates/form-for.js +1 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/.bower.json +15 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/.bowerrc +3 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/.gitignore +2 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/README.md +94 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/checkbox-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/color-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/date-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/datetime-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/email-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/form-errors.react.js +13 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/form-for.react.js +78 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/hidden-input.react.js +10 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/input.react.js +92 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/number-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/options-for-select.react.js +10 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/password-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/radio-input.react.js +10 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/select-input.react.js +17 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/submit-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/text-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/textarea-input.react.js +10 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/time-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/example/bower.json +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/example/index.html +6 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/example/js/app.js +76 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/example/react/app.jsx +76 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/gulpfile.js +39 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/package.json +12 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/src/bower.json +27 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/src/form-for.js +362 -0
- data/lib/generators/flux_on_rails/templates/react.js +18095 -0
- data/lib/generators/flux_on_rails/templates/stores/example-store.js +110 -0
- data/lib/generators/flux_on_rails/templates/tasks/react_tasks.rake +14 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e9c16b33be38701e19bfde520bf1ef5421791a5
|
4
|
+
data.tar.gz: 04857336ca59b89e15c6fbe006d2a9e58a61b061
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 654895bb308f17dc12d6a1e6167aedfbe1ad5dec01ef4e9df7b43c1e7d22074c17d622d0ac25c0fb2f4aedf8206c6fe15317b5d8cedfb2c4dab70bab559628ee
|
7
|
+
data.tar.gz: ac009cf993b6442682708fb929e82baa8edc23335d0249ea0ff71d90470c93ee618be13038e2b5323a2d44e9a304a9c61e431d9eff634dcb732986749448c629
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ed Shadi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# FluxOnRails
|
2
|
+
Generate basic React and Flux structure:
|
3
|
+
- **react.js file:** from Facebook
|
4
|
+
- **dispatcher.js file:** from Facebook
|
5
|
+
- **app/assets/components directory:** this is where you'll do all of your React component work with jsx
|
6
|
+
- **app/assets/javascripts/components directory:** transformed React components jsx => js
|
7
|
+
- **app/assets/javascripts/actions directory:** flux actions
|
8
|
+
- **app/assets/javascripts/dispatchers directory:** flux dispatchers
|
9
|
+
- **app/assets/javascripts/stores directory:** flux stores
|
10
|
+
- **app/assets/javascripts/constants directory:** flux constants
|
11
|
+
- **vendor/assets/javascripts/form-builder directory:** React plugin for building forms a la Rails. For documentation and useage: vendor/assets/javascripts/form-builder/README.md
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'flux_on_rails', group: :development
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install flux_on_rails
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# Generate sturcture and assets
|
33
|
+
rails g flux_on_rails:install
|
34
|
+
|
35
|
+
# Watch and transform the jsx components (keep that runing)
|
36
|
+
rake react:build
|
37
|
+
```
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/[my-github-username]/flux_on_rails/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flux_on_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flux_on_rails"
|
8
|
+
spec.version = FluxOnRails::VERSION
|
9
|
+
spec.authors = ["Ed Shadi"]
|
10
|
+
spec.email = ["edshadi@gmail.com"]
|
11
|
+
spec.summary = %q{Flux and React generators and setup for Rails}
|
12
|
+
spec.description = %q{Flux and React generators for Rails}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
module FluxOnRails
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
desc "Adds ReactJS and base folder structure"
|
7
|
+
|
8
|
+
def js_manifest
|
9
|
+
@js_manifest ||= find_or_create_js_manifest
|
10
|
+
end
|
11
|
+
def generate_assets
|
12
|
+
add_react
|
13
|
+
add_react_form_builder
|
14
|
+
add_flux_dispatcher
|
15
|
+
add_flux_dirs
|
16
|
+
add_tasks
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def find_or_create_js_manifest
|
21
|
+
manifest = 'app/assets/javascripts/application.js'
|
22
|
+
copy_file("application.js", manifest) unless File.exist?(manifest)
|
23
|
+
manifest
|
24
|
+
end
|
25
|
+
def add_react_form_builder
|
26
|
+
insert_into_file js_manifest, "//= require form-for\n", :after => "react\n"
|
27
|
+
directory 'react-form-for-object', 'vendor/assets/javascripts/react-form-for-object'
|
28
|
+
copy_file 'form-for.js', 'vendor/assets/javascripts/form-for.js'
|
29
|
+
end
|
30
|
+
def add_react
|
31
|
+
insert_into_file js_manifest, "//= require react\n", :after => "jquery_ujs\n"
|
32
|
+
copy_file 'react.js', 'vendor/assets/javascripts/react.js'
|
33
|
+
end
|
34
|
+
def add_flux_dispatcher
|
35
|
+
insert_into_file js_manifest, "//= require dispatcher\n", :after => "react\n"
|
36
|
+
copy_file 'dispatcher.js', 'vendor/assets/javascripts/dispatcher.js'
|
37
|
+
end
|
38
|
+
def add_flux_dirs
|
39
|
+
directory 'components', 'app/assets/components'
|
40
|
+
directory 'components', 'app/assets/javascripts/react'
|
41
|
+
directory 'stores', 'app/assets/javascripts/stores'
|
42
|
+
directory 'actions', 'app/assets/javascripts/actions'
|
43
|
+
directory 'constants', 'app/assets/javascripts/constants'
|
44
|
+
directory 'dispatchers', 'app/assets/javascripts/dispatchers'
|
45
|
+
end
|
46
|
+
def add_tasks
|
47
|
+
copy_file 'tasks/react_tasks.rake', 'lib/tasks/react_tasks.rake'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
//= require dispatchers/app-dispatcher
|
2
|
+
//= require constants/app-constants
|
3
|
+
var ExampleActions = {
|
4
|
+
createExample: function(data) {
|
5
|
+
AppDispatcher.handleViewAction({
|
6
|
+
type: AppConstants.CREATE_EXAMPLE,
|
7
|
+
data: data
|
8
|
+
})
|
9
|
+
},
|
10
|
+
updateExample: function(data) {
|
11
|
+
AppDispatcher.handleViewAction({
|
12
|
+
type: AppConstants.UPDATE_EXAMPLE,
|
13
|
+
data: data
|
14
|
+
})
|
15
|
+
},
|
16
|
+
destroyExample: function(id) {
|
17
|
+
AppDispatcher.handleViewAction({
|
18
|
+
type: AppConstants.DESTROY_EXAMPLE,
|
19
|
+
id: id
|
20
|
+
})
|
21
|
+
}
|
22
|
+
}
|
File without changes
|
@@ -0,0 +1,280 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2014, Facebook, Inc.
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
8
|
+
*
|
9
|
+
* @providesModule Dispatcher
|
10
|
+
* @typechecks
|
11
|
+
*/
|
12
|
+
/**
|
13
|
+
* Dispatcher is used to broadcast payloads to registered callbacks. This is
|
14
|
+
* different from generic pub-sub systems in two ways:
|
15
|
+
*
|
16
|
+
* 1) Callbacks are not subscribed to particular events. Every payload is
|
17
|
+
* dispatched to every registered callback.
|
18
|
+
* 2) Callbacks can be deferred in whole or part until other callbacks have
|
19
|
+
* been executed.
|
20
|
+
*
|
21
|
+
* For example, consider this hypothetical flight destination form, which
|
22
|
+
* selects a default city when a country is selected:
|
23
|
+
*
|
24
|
+
* var flightDispatcher = new Dispatcher();
|
25
|
+
*
|
26
|
+
* // Keeps track of which country is selected
|
27
|
+
* var CountryStore = {country: null};
|
28
|
+
*
|
29
|
+
* // Keeps track of which city is selected
|
30
|
+
* var CityStore = {city: null};
|
31
|
+
*
|
32
|
+
* // Keeps track of the base flight price of the selected city
|
33
|
+
* var FlightPriceStore = {price: null}
|
34
|
+
*
|
35
|
+
* When a user changes the selected city, we dispatch the payload:
|
36
|
+
*
|
37
|
+
* flightDispatcher.dispatch({
|
38
|
+
* actionType: 'city-update',
|
39
|
+
* selectedCity: 'paris'
|
40
|
+
* });
|
41
|
+
*
|
42
|
+
* This payload is digested by `CityStore`:
|
43
|
+
*
|
44
|
+
* flightDispatcher.register(function(payload)) {
|
45
|
+
* if (payload.actionType === 'city-update') {
|
46
|
+
* CityStore.city = payload.selectedCity;
|
47
|
+
* }
|
48
|
+
* });
|
49
|
+
*
|
50
|
+
* When the user selects a country, we dispatch the payload:
|
51
|
+
*
|
52
|
+
* flightDispatcher.dispatch({
|
53
|
+
* actionType: 'country-update',
|
54
|
+
* selectedCountry: 'australia'
|
55
|
+
* });
|
56
|
+
*
|
57
|
+
* This payload is digested by both stores:
|
58
|
+
*
|
59
|
+
* CountryStore.dispatchToken = flightDispatcher.register(function(payload) {
|
60
|
+
* if (payload.actionType === 'country-update') {
|
61
|
+
* CountryStore.country = payload.selectedCountry;
|
62
|
+
* }
|
63
|
+
* });
|
64
|
+
*
|
65
|
+
* When the callback to update `CountryStore` is registered, we save a reference
|
66
|
+
* to the returned token. Using this token with `waitFor()`, we can guarantee
|
67
|
+
* that `CountryStore` is updated before the callback that updates `CityStore`
|
68
|
+
* needs to query its data.
|
69
|
+
*
|
70
|
+
* CityStore.dispatchToken = flightDispatcher.register(function(payload) {
|
71
|
+
* if (payload.actionType === 'country-update') {
|
72
|
+
* // `CountryStore.country` may not be updated.
|
73
|
+
* flightDispatcher.waitFor([CountryStore.dispatchToken]);
|
74
|
+
* // `CountryStore.country` is now guaranteed to be updated.
|
75
|
+
*
|
76
|
+
* // Select the default city for the new country
|
77
|
+
* CityStore.city = getDefaultCityForCountry(CountryStore.country);
|
78
|
+
* }
|
79
|
+
* });
|
80
|
+
*
|
81
|
+
* The usage of `waitFor()` can be chained, for example:
|
82
|
+
*
|
83
|
+
* FlightPriceStore.dispatchToken =
|
84
|
+
* flightDispatcher.register(function(payload)) {
|
85
|
+
* switch (payload.actionType) {
|
86
|
+
* case 'country-update':
|
87
|
+
* flightDispatcher.waitFor([CityStore.dispatchToken]);
|
88
|
+
* FlightPriceStore.price =
|
89
|
+
* getFlightPriceStore(CountryStore.country, CityStore.city);
|
90
|
+
* break;
|
91
|
+
*
|
92
|
+
* case 'city-update':
|
93
|
+
* FlightPriceStore.price =
|
94
|
+
* FlightPriceStore(CountryStore.country, CityStore.city);
|
95
|
+
* break;
|
96
|
+
* }
|
97
|
+
* });
|
98
|
+
*
|
99
|
+
* The `country-update` payload will be guaranteed to invoke the stores'
|
100
|
+
* registered callbacks in order: `CountryStore`, `CityStore`, then
|
101
|
+
* `FlightPriceStore`.
|
102
|
+
*/
|
103
|
+
var Dispatcher = (function() {
|
104
|
+
var _lastID = 1;
|
105
|
+
var _prefix = 'ID_';
|
106
|
+
/**
|
107
|
+
* Use invariant() to assert state which your program assumes to be true.
|
108
|
+
*
|
109
|
+
* Provide sprintf-style format (only %s is supported) and arguments
|
110
|
+
* to provide information about what broke and what you were
|
111
|
+
* expecting.
|
112
|
+
*
|
113
|
+
* The invariant message will be stripped in production, but the invariant
|
114
|
+
* will remain to ensure logic does not differ in production.
|
115
|
+
*/
|
116
|
+
var invariant = function(condition, format, a, b, c, d, e, f) {
|
117
|
+
if (false) {
|
118
|
+
if (format === undefined) {
|
119
|
+
throw new Error('invariant requires an error message argument');
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
if (!condition) {
|
124
|
+
var error;
|
125
|
+
if (format === undefined) {
|
126
|
+
error = new Error(
|
127
|
+
'Minified exception occurred; use the non-minified dev environment ' +
|
128
|
+
'for the full error message and additional helpful warnings.'
|
129
|
+
);
|
130
|
+
} else {
|
131
|
+
var args = [a, b, c, d, e, f];
|
132
|
+
var argIndex = 0;
|
133
|
+
error = new Error(
|
134
|
+
'Invariant Violation: ' +
|
135
|
+
format.replace(/%s/g, function() { return args[argIndex++]; })
|
136
|
+
);
|
137
|
+
}
|
138
|
+
|
139
|
+
error.framesToPop = 1; // we don't care about invariant's own frame
|
140
|
+
throw error;
|
141
|
+
}
|
142
|
+
};
|
143
|
+
var _Dispatcher = function() {
|
144
|
+
"use strict";
|
145
|
+
this.$Dispatcher_callbacks = {};
|
146
|
+
this.$Dispatcher_isPending = {};
|
147
|
+
this.$Dispatcher_isHandled = {};
|
148
|
+
this.$Dispatcher_isDispatching = false;
|
149
|
+
this.$Dispatcher_pendingPayload = null;
|
150
|
+
}
|
151
|
+
/**
|
152
|
+
* Registers a callback to be invoked with every dispatched payload. Returns
|
153
|
+
* a token that can be used with `waitFor()`.
|
154
|
+
*
|
155
|
+
* @param {function} callback
|
156
|
+
* @return {string}
|
157
|
+
*/
|
158
|
+
_Dispatcher.prototype.register=function(callback) {"use strict";
|
159
|
+
var id = _prefix + _lastID++;
|
160
|
+
this.$Dispatcher_callbacks[id] = callback;
|
161
|
+
return id;
|
162
|
+
};
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Removes a callback based on its token.
|
166
|
+
*
|
167
|
+
* @param {string} id
|
168
|
+
*/
|
169
|
+
_Dispatcher.prototype.unregister=function(id) {"use strict";
|
170
|
+
invariant(
|
171
|
+
this.$Dispatcher_callbacks[id],
|
172
|
+
'Dispatcher.unregister(...): `%s` does not map to a registered callback.',
|
173
|
+
id
|
174
|
+
);
|
175
|
+
delete this.$Dispatcher_callbacks[id];
|
176
|
+
};
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Waits for the callbacks specified to be invoked before continuing execution
|
180
|
+
* of the current callback. This method should only be used by a callback in
|
181
|
+
* response to a dispatched payload.
|
182
|
+
*
|
183
|
+
* @param {array<string>} ids
|
184
|
+
*/
|
185
|
+
_Dispatcher.prototype.waitFor=function(ids) {"use strict";
|
186
|
+
invariant(
|
187
|
+
this.$Dispatcher_isDispatching,
|
188
|
+
'Dispatcher.waitFor(...): Must be invoked while dispatching.'
|
189
|
+
);
|
190
|
+
for (var ii = 0; ii < ids.length; ii++) {
|
191
|
+
var id = ids[ii];
|
192
|
+
if (this.$Dispatcher_isPending[id]) {
|
193
|
+
invariant(
|
194
|
+
this.$Dispatcher_isHandled[id],
|
195
|
+
'Dispatcher.waitFor(...): Circular dependency detected while ' +
|
196
|
+
'waiting for `%s`.',
|
197
|
+
id
|
198
|
+
);
|
199
|
+
continue;
|
200
|
+
}
|
201
|
+
invariant(
|
202
|
+
this.$Dispatcher_callbacks[id],
|
203
|
+
'Dispatcher.waitFor(...): `%s` does not map to a registered callback.',
|
204
|
+
id
|
205
|
+
);
|
206
|
+
this.$Dispatcher_invokeCallback(id);
|
207
|
+
}
|
208
|
+
};
|
209
|
+
|
210
|
+
/**
|
211
|
+
* Dispatches a payload to all registered callbacks.
|
212
|
+
*
|
213
|
+
* @param {object} payload
|
214
|
+
*/
|
215
|
+
_Dispatcher.prototype.dispatch=function(payload) {"use strict";
|
216
|
+
invariant(
|
217
|
+
!this.$Dispatcher_isDispatching,
|
218
|
+
'Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.'
|
219
|
+
);
|
220
|
+
this.$Dispatcher_startDispatching(payload);
|
221
|
+
try {
|
222
|
+
for (var id in this.$Dispatcher_callbacks) {
|
223
|
+
if (this.$Dispatcher_isPending[id]) {
|
224
|
+
continue;
|
225
|
+
}
|
226
|
+
this.$Dispatcher_invokeCallback(id);
|
227
|
+
}
|
228
|
+
} finally {
|
229
|
+
this.$Dispatcher_stopDispatching();
|
230
|
+
}
|
231
|
+
};
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Is this Dispatcher currently dispatching.
|
235
|
+
*
|
236
|
+
* @return {boolean}
|
237
|
+
*/
|
238
|
+
_Dispatcher.prototype.isDispatching=function() {"use strict";
|
239
|
+
return this.$Dispatcher_isDispatching;
|
240
|
+
};
|
241
|
+
|
242
|
+
/**
|
243
|
+
* Call the calback stored with the given id. Also do some internal
|
244
|
+
* bookkeeping.
|
245
|
+
*
|
246
|
+
* @param {string} id
|
247
|
+
* @internal
|
248
|
+
*/
|
249
|
+
_Dispatcher.prototype.$Dispatcher_invokeCallback=function(id) {"use strict";
|
250
|
+
this.$Dispatcher_isPending[id] = true;
|
251
|
+
this.$Dispatcher_callbacks[id](this.$Dispatcher_pendingPayload);
|
252
|
+
this.$Dispatcher_isHandled[id] = true;
|
253
|
+
};
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Set up bookkeeping needed when dispatching.
|
257
|
+
*
|
258
|
+
* @param {object} payload
|
259
|
+
* @internal
|
260
|
+
*/
|
261
|
+
_Dispatcher.prototype.$Dispatcher_startDispatching=function(payload) {"use strict";
|
262
|
+
for (var id in this.$Dispatcher_callbacks) {
|
263
|
+
this.$Dispatcher_isPending[id] = false;
|
264
|
+
this.$Dispatcher_isHandled[id] = false;
|
265
|
+
}
|
266
|
+
this.$Dispatcher_pendingPayload = payload;
|
267
|
+
this.$Dispatcher_isDispatching = true;
|
268
|
+
};
|
269
|
+
|
270
|
+
/**
|
271
|
+
* Clear bookkeeping used for dispatching.
|
272
|
+
*
|
273
|
+
* @internal
|
274
|
+
*/
|
275
|
+
_Dispatcher.prototype.$Dispatcher_stopDispatching=function() {"use strict";
|
276
|
+
this.$Dispatcher_pendingPayload = null;
|
277
|
+
this.$Dispatcher_isDispatching = false;
|
278
|
+
};
|
279
|
+
return _Dispatcher;
|
280
|
+
}())
|