slender_data 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cfa32663017a9b7ca26724ad84858d159ae78f1
4
- data.tar.gz: 7f96b6f3ce8b3a22b7691fe0ac241825e9b92dc7
3
+ metadata.gz: ad1f6ff2a238e3b68f7204ab22075983ec2bb710
4
+ data.tar.gz: d51c1b59474a55476518221e59aaf0532be40d72
5
5
  SHA512:
6
- metadata.gz: af231ee6588b729b8a870b9fde603ab2216b475017ee6ec27b050a0d5812174e558be056eb1076409a771aed13bc1e106e271939c0ded57f45cdf267061c29fb
7
- data.tar.gz: e0ac653466ac1637ab7e5d195199fa4406172ecdb8500ccf3dab55dc9c5a14ff4402fda92161d5f2db7b380063f6dee1df63e244ed83b987027aa006d806c7d8
6
+ metadata.gz: da7503aaf3a208e102a3993acfd4cc98043d24a3eb3faa56dfe6ee2a7c0d2636e75018b27b4bb91e354b71036ea9372bccf75446340cb3113314eec895711ff5
7
+ data.tar.gz: 9748a79bf0da516420de67e49d1410424a1b0774b5cd3ece06d553ef34bfa9dcd91bff74166f8d94cec11648db984b90ef40e7bad9f2a022bc4d495d120291f1
@@ -48,8 +48,8 @@ class slender_data.PersistenceManager
48
48
 
49
49
 
50
50
  # Adds the given data objects to the server cache.
51
- add_all: (data) ->
52
- @server_data.add_all data
51
+ add_all: (entries) ->
52
+ @add(entry) for entry in entries
53
53
 
54
54
 
55
55
  # Returns an array containing only the changed objects.
@@ -128,8 +128,8 @@ class slender_data.PersistenceManager
128
128
  # Fetches the entry with the given key from the server.
129
129
  # Adds it to the clientside cache.
130
130
  fetch: (key, success_callback) ->
131
- @loader.get "#{@base_url}/#{key}.json", (server_entry) =>
132
- client_entry = @add server_entry
131
+ @loader.get "#{@base_url}/#{key}.json", (server_response) =>
132
+ client_entry = @add server_response[@model_name]
133
133
  success_callback client_entry
134
134
 
135
135
 
@@ -142,7 +142,7 @@ class slender_data.PersistenceManager
142
142
  cache: no
143
143
  data: data
144
144
  success: (data) =>
145
- @server_data.add_all data
145
+ @add_all data
146
146
  success_callback(data) if success_callback
147
147
  error: (xhr) ->
148
148
  error_callback(xhr.responseText) if error_callback
@@ -194,10 +194,12 @@ class slender_data.PersistenceManager
194
194
  load_many: (ids, success_callback) ->
195
195
  [cached_entries, missing_ids] = @get_many ids
196
196
  if missing_ids.length == 0
197
- return success_callback(cached_entries)
198
-
199
- # TODO: implement loading the missing entries from the server.
200
- alert "uncached entries found: #{missing_ids}"
197
+ # All requested entries found in cache --> return them immediately.
198
+ success_callback(cached_entries)
199
+ else
200
+ # Entries missing --> load them from the server.
201
+ @fetch_all missing_ids, (server_snippets) ->
202
+ success_callback $.merge(cached_entries, server_snippets)
201
203
 
202
204
 
203
205
  # Saves the given object.
@@ -235,11 +237,8 @@ class slender_data.PersistenceManager
235
237
  type: 'PUT'
236
238
  data: data
237
239
  success: (server_response) =>
238
- server_obj = server_response[@model_name]
239
- @server_data.add server_obj
240
- client_obj = slender_data.clone_hash server_obj
241
- @client_data.add client_obj
242
- success_callback client_obj if success_callback
240
+ @client_entry = @add server_response[@model_name]
241
+ success_callback @client_entry if success_callback
243
242
  error: (xhr) ->
244
243
  error_callback(xhr.responseText) if error_callback
245
244
 
@@ -1,3 +1,3 @@
1
1
  module SlenderData
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slender_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Goslar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2013-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails