Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

33
LINES

< > BotCompany Repo | #1027315 // dm_fieldLiveValueWithConversions

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10210L/72K).

static <A, B> SimpleLiveValue dm_fieldLiveValueWithConversions(S fieldName, Class<A> type, IF1<B, A> convertFromField, IF1<A, B> convertToField) {
  ret dm_fieldLiveValueWithConversions(dm_current_mandatory(), fieldName, type, convertFromField, convertToField);
}

static <A, B> SimpleLiveValue dm_fieldLiveValueWithConversions(S fieldName, Class<A> type, F1<B, A> convertFromField, F1<A, B> convertToField) {
  ret dm_fieldLiveValueWithConversions(dm_current_mandatory(), fieldName, type, convertFromField, convertToField);
}

static <A, B> SimpleLiveValue dm_fieldLiveValueWithConversions(DynModule module, S fieldName, Class<A> type, IF1<B, A> convertFromField, IF1<A, B> convertToField) {
  lock module.lock;
  temp module.enter(); // for dm_watchField
  SimpleLiveValue<A> value = new(type, convertFromField.get((B) get(module, fieldName)));
  dm_watchField(fieldName, r {
    value.set(convertFromField.get((B) get(module, fieldName)));
  });
  value.onChange(r {
    module.setField(fieldName, convertToField.get(value!));
  });
  ret value;
}

static <A, B> SimpleLiveValue dm_fieldLiveValueWithConversions(DynModule module, S fieldName, Class<A> type, F1<B, A> convertFromField, F1<A, B> convertToField) {
  lock module.lock;
  temp module.enter(); // for dm_watchField
  SimpleLiveValue<A> value = new(type, convertFromField.get((B) get(module, fieldName)));
  dm_watchField(fieldName, r {
    value.set(convertFromField.get((B) get(module, fieldName)));
  });
  value.onChange(r {
    module.setField(fieldName, convertToField.get(value!));
  });
  ret value;
}

Author comment

Began life as a copy of #1015971

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027315
Snippet name: dm_fieldLiveValueWithConversions
Eternal ID of this version: #1027315/6
Text MD5: 37aae8f7fd668acdf44ad92fc1f9d84c
Transpilation MD5: f0b1767ea43f4efaade7b2fba3f1101b
Author: stefan
Category: javax / stefan's os
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-02 16:29:04
Source code size: 1604 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 124 / 197
Version history: 5 change(s)
Referenced in: [show references]