Skip to content

Commit

Permalink
🛠 Refactor: Update RNIIdentifiable
Browse files Browse the repository at this point in the history
Summary:
* Update `RNIIdentifiable` to use `RNIObjectMetadata`.
* Update `UIWindow+Helpers` to use `RNIObjectMetadata`.
  • Loading branch information
dominicstop committed Mar 30, 2023
1 parent cdcba0c commit 2fc59ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ios/src_library/Extensions/UIWindow+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import Foundation

extension UIWindow: RNIIdentifiable {
extension UIWindow: RNIObjectMetadata, RNIIdentifiable {
public static var synthesizedIdPrefix = "window-id-";
};
18 changes: 6 additions & 12 deletions ios/src_library/Helpers+Utilities/RNIIdentifiable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

fileprivate final class RNIObjectIdentifier {
public final class RNIObjectIdentifier {
static var counterID = -1;

let id: Int = {
Expand All @@ -18,15 +18,8 @@ fileprivate final class RNIObjectIdentifier {
let uuid = UUID();
};

fileprivate final class RNIObjectIdentifierMap {
static let map = NSMapTable<AnyObject, RNIObjectIdentifier>(
keyOptions: .weakMemory,
valueOptions: .strongMemory
);
};


public protocol RNIIdentifiable: AnyObject {
public protocol RNIIdentifiable:
AnyObject, RNIObjectMetadata where T == RNIObjectIdentifier {

static var synthesizedIdPrefix: String { set get };

Expand All @@ -37,13 +30,14 @@ public protocol RNIIdentifiable: AnyObject {
};

extension RNIIdentifiable {

fileprivate var identifier: RNIObjectIdentifier {
if let identifier = RNIObjectIdentifierMap.map.object(forKey: self) {
if let identifier = self.metadata {
return identifier;
};

let identifier = RNIObjectIdentifier();
RNIObjectIdentifierMap.map.setObject(identifier, forKey: self);
self.metadata = identifier;

return identifier;
};
Expand Down

0 comments on commit 2fc59ee

Please sign in to comment.