Skip to content

Commit 2f9b440

Browse files
committed
Update readme to include latest features
1 parent 84a70c1 commit 2f9b440

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,48 @@ class Sync.TodoListRow extends Sync.View
222222

223223
```
224224

225+
## Narrowing sync_new scope
226+
227+
View:
228+
```erb
229+
<%= sync_new partial: 'todo_list_row', resource: Todo.new, scope: [@project, :staff] %>
230+
```
231+
232+
Controller/Model:
233+
```ruby
234+
sync_new @todo, scope: [@project, :staff]
235+
```
236+
237+
238+
## Refetching Partials
239+
240+
Refetching allows syncing partials across different users when the partial requires the session's context (ie. current_user).
241+
242+
Ex:
243+
View: Add `refetch: true` to sync calls, and place partial file in a 'refetch'
244+
subdirectory in the model's sync view folder:
245+
246+
The partial file would be located in `app/views/sync/todos/refetch/_list_row.html.erb`
247+
```erb
248+
<% @project.todos.ordered.each do |todo| %>
249+
<%= sync partial: 'list_row', resource: todo, refetch: true %>
250+
<% end %>
251+
<%= sync_new partial: 'list_row', resource: Todo.new, scope: @project, refetch: true %>
252+
```
253+
254+
*Notes*
255+
256+
While this approach works very well for the cases it's needed, syncing without refetching should be used unless refetching is absolutely necessary for performance reasons. For example,
257+
258+
A sync update request is triggered on the server for a 'regular' sync'd partial with 100 listening clients:
259+
- number of http requests 1
260+
- number of renders 1, pushed out to all 100 clients via pubsub server.
261+
262+
263+
A sync update request is triggered on the server for a 'refetch' sync'd partial with 100 listening clients:
264+
- number of http requests 100
265+
- number of renders 100, rendering each request in clients session context.
266+
225267
## Using with cache_digests (Russian doll caching)
226268

227269
Sync has a custom `DependencyTracker::ERBTracker` that can handle `sync` render calls.

0 commit comments

Comments
 (0)