001package arez.persist.runtime.browser;
002
003import arez.persist.StoreTypes;
004import arez.persist.runtime.ArezPersist;
005import javax.annotation.Nonnull;
006
007public final class ArezPersistBrowserUtil
008{
009  private ArezPersistBrowserUtil()
010  {
011  }
012
013  /**
014   * Register a store under the {@link StoreTypes#SESSION} name that saves state in a browsers session storage.
015   *
016   * @param persistenceKey the key under which the state is stored.
017   */
018  public static void registerSessionStore( @Nonnull final String persistenceKey )
019  {
020    ArezPersist.registerStore( StoreTypes.SESSION, WebStorageService.createSessionStorageService( persistenceKey ) );
021  }
022
023  /**
024   * Register a store under the {@link StoreTypes#LOCAL} name that saves state in a browsers local storage.
025   *
026   * @param persistenceKey the key under which the state is stored.
027   */
028  public static void registerLocalStore( @Nonnull final String persistenceKey )
029  {
030    ArezPersist.registerStore( StoreTypes.LOCAL, WebStorageService.createLocalStorageService( persistenceKey ) );
031  }
032
033  /**
034   * Register a character converter that is useful when converting to json representation.
035   */
036  public static void registerCharacterConverter()
037  {
038    ArezPersist.registerConverter( Character.class, new CharacterConverter() );
039  }
040
041  /**
042   * Register a byte converter that is useful when converting to json representation.
043   */
044  public static void registerByteConverter()
045  {
046    ArezPersist.registerConverter( Byte.class, new ByteConverter() );
047  }
048
049  /**
050   * Register a Short converter that is useful when converting to json representation.
051   */
052  public static void registerShortConverter()
053  {
054    ArezPersist.registerConverter( Short.class, new ShortConverter() );
055  }
056
057  /**
058   * Register a Integer converter that is useful when converting to json representation.
059   */
060  public static void registerIntegerConverter()
061  {
062    ArezPersist.registerConverter( Integer.class, new IntegerConverter() );
063  }
064
065  /**
066   * Register a Long converter that is useful when converting to json representation.
067   */
068  public static void registerLongConverter()
069  {
070    ArezPersist.registerConverter( Long.class, new LongConverter() );
071  }
072
073  /**
074   * Register a Float converter that is useful when converting to json representation.
075   */
076  public static void registerFloatConverter()
077  {
078    ArezPersist.registerConverter( Float.class, new FloatConverter() );
079  }
080}