-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathLBPersistedModel.h
112 lines (97 loc) · 3.93 KB
/
LBPersistedModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* @file LBPersistedModel.h
*
* @author Michael Schoonmaker
* @copyright (c) 2013 StrongLoop. All rights reserved.
*/
#import "LBModel.h"
// The following typedefs are not used anymore but left for backward compatibility.
@class LBPersistedModel;
typedef void (^LBPersistedModelObjectSuccessBlock)(LBPersistedModel *model) __deprecated;
typedef void (^LBPersistedModelArraySuccessBlock)(NSArray *array) __deprecated;
typedef void (^LBPersistedModelVoidSuccessBlock)() __deprecated;
typedef void (^LBPersistedModelBoolSuccessBlock)(BOOL boolean) __deprecated;
typedef void (^LBPersistedModelNumberSuccessBlock)(NSInteger number) __deprecated;
/**
* A local representative of a single persisted model instance on the server.
* The key difference from LBModel is that this implements the CRUD operation supports.
*/
@interface LBPersistedModel : LBModel
/** All Models have a numerical `id` field. */
@property (nonatomic, readonly, copy) id _id;
/**
* Blocks of this type are executed when LBPersistedModel::saveWithSuccess:failure: is
* successful.
*/
typedef void (^LBPersistedModelSaveSuccessBlock)();
/**
* Saves the LBPersistedModel to the server.
*
* Calls `toDictionary` to determine which fields should be saved.
*
* @param success The block to be executed when the save is successful.
* @param failure The block to be executed when the save fails.
*/
- (void)saveWithSuccess:(LBPersistedModelSaveSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when LBPersistedModel::destroyWithSuccess:failure: is
* successful.
*/
typedef void (^LBPersistedModelDestroySuccessBlock)();
/**
* Destroys the LBPersistedModel from the server.
*
* @param success The block to be executed when the destroy is successful.
* @param failure The block to be executed when the destroy fails.
*/
- (void)destroyWithSuccess:(LBPersistedModelDestroySuccessBlock)success
failure:(SLFailureBlock)failure;
@end
/**
* A local representative of a single model type on the server, encapsulating
* the name of the model type for easy LBPersistedModel creation, discovery, and
* management.
*/
@interface LBPersistedModelRepository : LBModelRepository
//typedef void (^LBPersistedModelExistsSuccessBlock)(BOOL exists);
//- (void)existsWithId:(id)_id
// success:(LBPersistedModelExistsSuccessBlock)success
// failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBModelRepository::findById:success:failure: is successful.
*/
typedef void (^LBPersistedModelFindSuccessBlock)(LBPersistedModel *model);
/**
* Finds and downloads a single instance of this model type on and from the
* server with the given id.
*
* @param _id The id to search for.
* @param success The block to be executed when the destroy is successful.
* @param failure The block to be executed when the destroy fails.
*/
- (void)findById:(id)_id
success:(LBPersistedModelFindSuccessBlock)success
failure:(SLFailureBlock)failure;
/**
* Blocks of this type are executed when
* LBPersistedModelRepository::allWithSuccess:failure: is successful.
*/
typedef void (^LBPersistedModelAllSuccessBlock)(NSArray *models);
/**
* Finds and downloads all models of this type on and from the server.
*
* @param success The block to be executed when the destroy is successful.
* @param failure The block to be executed when the destroy fails.
*/
- (void)allWithSuccess:(LBPersistedModelAllSuccessBlock)success
failure:(SLFailureBlock)failure;
typedef void (^LBPersistedModelFindOneSuccessBlock)(LBPersistedModel *model);
- (void)findOneWithFilter:(NSDictionary *)filter
success:(LBPersistedModelFindOneSuccessBlock)success
failure:(SLFailureBlock)failure;
- (void)findWithFilter:(NSDictionary *)filter
success:(LBPersistedModelAllSuccessBlock)success
failure:(SLFailureBlock)failure;
@end