Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit c7eb977

Browse files
committed
basics are working
1 parent e3cc02a commit c7eb977

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+9631
-132
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
source 'https://rubygems.org'
22

3-
# Specify your gem's dependencies in syncromesh.gemspec
3+
# Specify your gem's dependencies in synchromesh.gemspec
44
gemspec

README.md

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,79 @@
1-
# Syncromesh
1+
# Synchromesh ![](logo.jpg?raw=true)
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/syncromesh`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
Synchromesh provides multi-client synchronization for [reactive-record](https://github.com/catprintlabs/reactive-record)
44

5-
TODO: Delete this and the text above, and describe your gem
5+
In otherwords browser 1 creates, updates, or destroys a model, and the changes are broadcast to all other clients.
6+
7+
Add the gem, setup the configuration, and synchromesh does the rest.
8+
9+
## Transports
10+
11+
Currently there are two transport mechanisms:
12+
13+
+ [Pusher](http://pusher.com) which gives you zero config websockets.
14+
+ Short cycle polling (for development)
15+
16+
As soon as Opal is working on Rails 5, we will add ActionCable.
17+
18+
Also near term we will have a simple mechanism to plug in your own transport.
19+
20+
## Security [NOT IMPLEMENTED YET]
21+
22+
Synchromesh builds on top of ReactiveRecord's model-based permission mechanism:
23+
24+
Each *user* gets a private transport channel. Before broadcasting an update to a users channel Synchromesh filters the data based on that users permissions.
625

726
## Installation
827

928
Add this line to your application's Gemfile:
1029

1130
```ruby
12-
gem 'syncromesh'
31+
gem 'synchromesh'
1332
```
1433

1534
And then execute:
1635

17-
$ bundle
36+
$ bundle install
1837

19-
Or install it yourself as:
38+
Also you must `require 'synchromesh'` from your client side code. The easiest way is to
39+
find the `require 'reactive-record'` line (typically in `components.rb`) and add `require 'synchromesh'` directly below it.
2040

21-
$ gem install syncromesh
41+
## Configuration
2242

23-
## Usage
43+
Add an initializer like this:
2444

25-
TODO: Write usage instructions here
45+
```ruby
46+
# for rails this would go in: config/initializers/synchromesh.rb
47+
Synchromesh.configuration do |config|
2648

27-
## Development
49+
config.transport = :pusher # set to :none to turn off, or to :simple_poller (see below)
50+
51+
config.app_id = '2xxxx2'
52+
config.key = 'dxxxxxxxxxxxxxxxxxx9'
53+
config.secret = '2xxxxxxxxxxxxxxxxxx2'
54+
config.channel_prefix = 'synchromesh' # this can be any string
55+
56+
# config.client_logging = false # default is true
2857

29-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58+
# simple_poller - good for debug or while developing on a plane... does NOT use long polling, so is not
59+
# workable for production
3060

31-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61+
# config.transport = :simple_poller
62+
# config.seconds_between_poll = 5 # default is 0.5
63+
# config.seconds_polled_data_will_be_retained = 1.hour # clears channel data after this time, default is 5 minutes,
64+
65+
end
66+
```
67+
68+
## Development
69+
70+
TBD
3271

3372
## Contributing
3473

35-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/syncromesh. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
74+
Bug reports and pull requests are welcome on GitHub at https://github.com/reactive-ruby/synchromesh. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
3675

3776

3877
## License
3978

4079
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41-

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

33
require "bundler/setup"
4-
require "syncromesh"
4+
require "synchromesh"
55

66
# You can add fixtures and/or initialization code here to make experimenting
77
# with your gem easier. You can also use a different console, if you like.

design.md

Whitespace-only changes.

lib/reactive_record/syncromesh.rb.erb renamed to lib/reactive_record/synchromesh.rb.erb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ReactiveRecord
22

3-
class Syncromesh
3+
class Synchromesh
44

55
include React::IsomorphicHelpers
66

@@ -19,8 +19,9 @@ module ReactiveRecord
1919

2020
before_first_mount do |context|
2121
if on_opal_client?
22+
puts "setting up synchromesh on client: <%= Synchromesh.transport %> time now = <%= Time.now %>"
2223

23-
<% if Syncromesh.transport == :pusher %>
24+
<% if Synchromesh.transport == :pusher %>
2425

2526
change = lambda do |data|
2627
sync_change Hash.new(data)
@@ -31,34 +32,38 @@ module ReactiveRecord
3132
end
3233

3334
%x{
34-
<% if Syncromesh.client_logging %>
35+
<% if Synchromesh.client_logging %>
3536
Pusher.log = function(message) {
3637
if (window.console && window.console.log) {
3738
window.console.log(message);
3839
}
3940
};
4041
<% end %>
4142

42-
var pusher = new Pusher('<%= Syncromesh.key %>', {
43-
encrypted: <%= Syncromesh.encrypted %>
44-
});
43+
<% if defined?(PusherFake) %>
44+
var pusher = <%= PusherFake.javascript %>;
45+
<% else %>
46+
var pusher = new Pusher('<%= Synchromesh.key %>', {
47+
encrypted: <%= Synchromesh.encrypted %>
48+
});
49+
<% end %>
4550

46-
var channel = pusher.subscribe('<%= Syncromesh.channel %>');
51+
var channel = pusher.subscribe('<%= Synchromesh.channel %>');
4752
channel.bind('change', change);
4853
channel.bind('destroy', destroy);
4954
}
5055

51-
<% elsif Syncromesh.transport == :simple_poller %>
56+
<% elsif Synchromesh.transport == :simple_poller %>
5257

5358
id = nil
5459

5560
HTTP.get(`window.ReactiveRecordEnginePath`+"/syncromesh-subscribe/").then do |response|
5661
id = response.json[:id]
5762
end
5863

59-
puts "SECONDS BETWEEN POLL SET TO <%= Syncromesh.seconds_between_poll %> SECONDS"
64+
puts "SECONDS BETWEEN POLL SET TO <%= Synchromesh.seconds_between_poll %> SECONDS"
6065

61-
every(<%= Syncromesh.seconds_between_poll %>) do
66+
every(<%= Synchromesh.seconds_between_poll %>) do
6267
HTTP.get(`window.ReactiveRecordEnginePath`+"/syncromesh-read/#{id}").then do |response|
6368
response.json.each do |update|
6469
case update[0]

0 commit comments

Comments
 (0)