Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Nov 20, 2019

Description

  • Move shared_preferences one level down to make room for new packages.
  • Add package:shared_preferences_platform_interface containing the core interface.
  • Copy method channel implementation and tests into the new package.

There are no changes in package:shared_preferences yet other than moving the files.

Related Issues

First step towards flutter/flutter#35116

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me!

       .-.
      :   ;
       "."
       / \
      /  |
    .'    \
   /.'   `.\
   ' \    ``.
     _`.____ `-._
    /^^^^^^^^`.\^\
   /           `  \ (PS)
""""""""""""""""""""""""
    SEAL OF APPROVAL
""""""""""""""""""""""""

@harryterkelsen
Copy link
Contributor

As we discussed offline, please make sure that you add the static instance setters and associated checks and comments. See here for an example.

@yjbanov
Copy link
Contributor Author

yjbanov commented Nov 21, 2019

@hterkelsen

As we discussed offline, please make sure that you add the static instance setters and associated checks and comments.

Done. PTAL.

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to update the homepage: in the pubspec.yaml for the original shared_preferences plugin, since you moved it. And you'll also need to bump the version of the shared_preferences so the new homepage is picked up in pub.

@yjbanov
Copy link
Contributor Author

yjbanov commented Nov 22, 2019

@hterkelsen

You also need to update the homepage: in the pubspec.yaml for the original shared_preferences plugin, since you moved it. And you'll also need to bump the version of the shared_preferences so the new homepage is picked up in pub.

Done: 8466e66

@yjbanov
Copy link
Contributor Author

yjbanov commented Nov 22, 2019

@hterkelsen I think I found a more ergonomic way for overriding statics, such as getInstance and setMockInitialValues. I added an indirection via SharedPreferencesBinding that controls creation and mocking of SharedPreferencesPlatform implementations. This indirection allows keeping all interfaces, including static methods, intact.

1a920f1

@yjbanov yjbanov force-pushed the web-shared-preferences branch 2 times, most recently from 29f6190 to 100097a Compare November 23, 2019 01:52
@yjbanov
Copy link
Contributor Author

yjbanov commented Nov 23, 2019

Ok, so after chatting with @hterkelsen we agreed to redesign it. The new design only abstracts away the method channel rather than all of SharedPreferences. The new interface is SharedPreferencesStorePlatform and it is only concerned about persisting key/value pairs. The caching and prefixing logic stays in SharedPreferences.

PTAL

/// Stores data in memory.
///
/// Data does not persist across application restarts. This is useful in unit-tests.
class InMemorySharedPreferencesStore extends SharedPreferencesStorePlatform {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@ditman
Copy link
Member

ditman commented Nov 23, 2019

The new version seems to reduce significantly the amount of code that other implementors need to write, I like it! (Note that the analyzer is screaming at a couple of minor things)

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@collinjackson collinjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one suggested change, LGTM otherwise


/// This does not do anything.
///
/// It is only here for backwards-compatibility.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this comment confusing. This is the 1.0 version of the platform interface, so there's no need to be backwards compatible. Can we just remove it instead of baking this flaw into the platform API forever? Deprecating/removing commit from the app-facing API can be done later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the plugin sends a commit message over to the Java/Objective-C side via a platform channel. I don't know how breaking it would be to stop sending this message, but I was thinking of adding Web support without breaking changes. However, if you are OK with it I'll remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked the iOS and Android implementations, and they just return true when they get a commit call. I think we should remove it from the platform interface, and when you migrate the plugin, just have commit return true directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@yjbanov yjbanov force-pushed the web-shared-preferences branch from 765d25e to fd3518d Compare November 26, 2019 00:32
@collinjackson collinjackson self-requested a review November 26, 2019 01:16
@yjbanov yjbanov merged commit 2ea4bc8 into flutter:master Nov 26, 2019
@ditman
Copy link
Member

ditman commented Nov 26, 2019

Yay, thanks @yjbanov!!

Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yjbanov this change left analysis_options.yaml in the top level directory shared_preferences instead of also moving it into shared_preferences/shared_preferences, which means that all the existing lint failures from the current shared_preferences plugin will also be ignored in the new shared_platform_interface too. Would it be possible for you to move the lint exclusions to the old package and fix any potentially failing issues in the new one? Also filed flutter/flutter#45627 to track.

sungmin-park pushed a commit to sungmin-park/flutter-plugins that referenced this pull request Dec 17, 2019
* add shared_preferences_platform_interface
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants