-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a centralized configuration API #747
Merged
Merged
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
2c7e050
Update the dangerfile
1de26b4
Make a trivial change to test new dangerfile
13fccb0
Try out the new value with another trivial change
c4b4d09
Add a configuration API to make a unified place for pulling config fr…
6968445
Specify properties for delegate
348e5c2
Finish removing text experiment global enable
f7bd45a
Generate the config file
2233852
Clean up configuration to fix tests
1044620
Work on making it serializable
d02b36f
Merge branch 'master' into AHExperiments
Adlai-Holler 75922a3
Finish it up
9801560
Fix example code
99b3a70
Update sample project
241eec9
Merge branch 'master' into AHExperiments
Adlai-Holler e4f6aac
Merge branch 'master' into AHExperiments
appleguy 042d338
Clean up a few things
50383b5
Merge branch 'master' into AHExperiments
a548185
Align with new project order
9ab0562
Make it faster and update license header
0edeb2f
Add an option to specify your config at compile time
9938217
Update another license header
4363c6c
Add a version field, and bring interface state coalescing into config…
1d4ba50
Update CA queue code
5c5e93d
Update CATransactionQueue tests
8cb7b8e
Turn transaction queue on by default (for now, see comment)
681bebd
Update the tests
16fab3f
Update the tests AGAIN
331d70d
Merge branch 'master' into AHExperiments
Adlai-Holler 73efad5
Remove unused ordered set
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"id": "configuration.json", | ||
"title": "configuration", | ||
"description" : "Schema definition of a Texture Configuration", | ||
"$schema": "http://json-schema.org/schema#", | ||
"type": "object", | ||
"properties": { | ||
"experimental_features": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"enum": [ | ||
"exp_graphics_contexts", | ||
"exp_text_node" | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// ASConfiguration.h | ||
// Texture | ||
// | ||
// Copyright (c) 2018-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <AsyncDisplayKit/ASBaseDefines.h> | ||
#import <AsyncDisplayKit/ASExperimentalFeatures.h> | ||
|
||
@protocol ASConfigurationDelegate; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
AS_SUBCLASSING_RESTRICTED | ||
@interface ASConfiguration : NSObject <NSCopying> | ||
|
||
/** | ||
* Create a configuration from the provided JSON object. | ||
* The mapping follows the schema in `configuration.json`. | ||
*/ | ||
- (instancetype)initWithJSONObject:(NSDictionary *)jsonObject; | ||
|
||
/** | ||
* The delegate for configuration-related events. | ||
* Delegate methods are called from a serial queue. | ||
*/ | ||
@property (strong, nullable) id<ASConfigurationDelegate> delegate; | ||
|
||
/** | ||
* The experimental features to enable in Texture. | ||
* See ASExperimentalFeatures for functions to convert to/from a string array. | ||
*/ | ||
@property ASExperimentalFeatures experimentalFeatures; | ||
|
||
@end | ||
|
||
/** | ||
* Implement this method in a category to make your | ||
* configuration available to Texture. It will be read | ||
* only once and copied. | ||
*/ | ||
@interface ASConfiguration (UserProvided) | ||
+ (ASConfiguration *)textureConfiguration; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// ASConfiguration.m | ||
// Texture | ||
// | ||
// Copyright (c) 2018-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <AsyncDisplayKit/ASConfiguration.h> | ||
#import <AsyncDisplayKit/ASConfigurationInternal.h> | ||
|
||
/// Not too performance-sensitive here. | ||
|
||
/// Get this from C++, without the extra exception handling. | ||
#define autotype __auto_type | ||
|
||
@implementation ASConfiguration | ||
|
||
- (instancetype)initWithJSONObject:(NSDictionary *)jsonObject | ||
{ | ||
if (self = [self init]) { | ||
autotype featureStrings = ASDynamicCast(jsonObject[@"experimental_features"], NSArray); | ||
self.experimentalFeatures = ASExperimentalFeaturesFromArray(featureStrings); | ||
} | ||
return self; | ||
} | ||
|
||
- (id)copyWithZone:(NSZone *)zone | ||
{ | ||
ASConfiguration *config = [[ASConfiguration alloc] init]; | ||
config.experimentalFeatures = self.experimentalFeatures; | ||
config.delegate = self.delegate; | ||
return config; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// ASConfigurationDelegate.h | ||
// Texture | ||
// | ||
// Copyright (c) 2018-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <AsyncDisplayKit/ASConfiguration.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* Used to communicate configuration-related events to the client. | ||
*/ | ||
@protocol ASConfigurationDelegate <NSObject> | ||
@optional | ||
|
||
/** | ||
* Texture performed its first behavior related to the feature(s). | ||
* This can be useful for tracking the impact of the behavior (A/B testing). | ||
*/ | ||
- (void)textureDidActivateExperimentalFeatures:(ASExperimentalFeatures)features; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// ASExperimentalFeatures.h | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai on 1/15/18. | ||
// Copyright © 2018 Facebook. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <AsyncDisplayKit/ASBaseDefines.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
ASDISPLAYNODE_EXTERN_C_BEGIN | ||
|
||
/** | ||
* A bit mask of features. | ||
*/ | ||
typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) { | ||
ASExperimentalGraphicsContexts = 1 << 0, // exp_graphics_contexts | ||
ASExperimentalTextNode = 1 << 1, // exp_text_node | ||
ASExperimentalFeatureAll = 0xFFFFFFFF | ||
}; | ||
|
||
/// Convert flags -> name array. | ||
NSArray<NSString *> *ASExperimentalFeaturesGetNames(ASExperimentalFeatures flags); | ||
|
||
/// Convert name array -> flags. | ||
ASExperimentalFeatures ASExperimentalFeaturesFromArray(NSArray<NSString *> *array); | ||
|
||
ASDISPLAYNODE_EXTERN_C_END | ||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// ASExperimentalFeatures.m | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai on 1/15/18. | ||
// Copyright © 2018 Facebook. All rights reserved. | ||
// | ||
|
||
#import <AsyncDisplayKit/ASExperimentalFeatures.h> | ||
|
||
NSArray<NSString *> *ASExperimentalFeaturesGetNames(ASExperimentalFeatures flags) | ||
{ | ||
NSArray *allNames = ASCreateOnce((@[@"exp_graphics_contexts", | ||
@"exp_text_node"])); | ||
|
||
if (flags == ASExperimentalFeatureAll) { | ||
return allNames; | ||
} | ||
|
||
// Go through all names, testing each bit. | ||
NSUInteger i = 0; | ||
return ASArrayByFlatMapping(allNames, NSString *name, ({ | ||
(flags & (1 << i++)) ? name : nil; | ||
})); | ||
} | ||
|
||
// O(N^2) but with counts this small, it's probably faster | ||
// than hashing the strings. | ||
ASExperimentalFeatures ASExperimentalFeaturesFromArray(NSArray<NSString *> *array) | ||
{ | ||
NSArray *allNames = ASExperimentalFeaturesGetNames(ASExperimentalFeatureAll); | ||
ASExperimentalFeatures result = 0; | ||
for (NSString *str in array) { | ||
NSUInteger i = [allNames indexOfObject:str]; | ||
if (i != NSNotFound) { | ||
result |= (1 << i); | ||
} | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very exciting, can't wait to see this list grow :).
I wonder how we should handle configuration for other values, like floating points, for e.g. range tuning parameter default values?
Or even a pattern of a configuration payload that is passed into certain components, like ASCollectionNode, where there is a default and it can be overridden on a per-instance basis (optionally) -- that's the case where range tuning would be very useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For more complex values, I don't think it'll be hard. We just update the configuration schema to add more fields. Range tuning param sets would be probably be in their very own schema. Thoughts?