JSPatch Introduction

318643095c83b914cf80a7f99f247fe6?s=47 Wei Wang
August 06, 2015

JSPatch Introduction

318643095c83b914cf80a7f99f247fe6?s=128

Wei Wang

August 06, 2015
Tweet

Transcript

  1. ࣗݾ঺հ w ԦቨʢΦ΢ΪPOFWDBUʣ+1 w -JOF"ET -JOFόΠτ (BNF$BTU 5IVOEFS  w

    IUUQTHJUIVCDPNPOFWDBU w IUUQPOFWDBU
  2. ੈքҰ൪ͷ ϓϩάϥϛϯάݴޠʁ

  3. +BWB4DSJQUؒҧ͍ͳ͍ IUUQHJUIVUJOGP

  4. +BWB4DSJQU$PSF J04

  5. +BWB4DSJQU$PSF var num = 5 + 5 var triple =

    function(value) { return value * 3} triple(num) //30 import JavaScriptCore let context = JSContext() context.evaluateScript("var num = 5 + 5") context.evaluateScript("var triple = function(value) { return value * 3 }") let tripleNum: JSValue = context.evaluateScript("triple(num)") +BWB4DSJQU 4XJGU
  6. import JavaScriptCore let context = JSContext() context.evaluateScript("var num = 5

    + 5") context.evaluateScript("var triple = function(value) { return value * 3 }") let tripleNum: JSValue = context.evaluateScript("triple(num)") 1MBJO4USJOH'VODUJPOBMJUZ
  7. import JavaScriptCore let context = JSContext() context.evaluateScript("var num = 5

    + 5") context.evaluateScript("var triple = function(value) { return value * 3 }") let tripleNum: JSValue = context.evaluateScript("triple(num)") 1MBJO4USJOH'VODUJPOBMJUZ 3VOUJNF
  8. +41BUDI Ԧቨ

  9. +BWB4DSJQUΛ࢖ͬͯɺ ΞϓϦͷϝιʔυΛࠩ͠ସ͑ΔϥΠϒϥϦʔ +41BUDIͱ͸ IUUQTHJUIVCDPNCBOH+41BUDI

  10. 8IZ w "QQਃ੥ͱϨϏϡʔ ஗͍ w ಛٸਃ੥೥੍ؒݶ w मਖ਼͚ͩͰ͸ͳ͘ɺػ ೳ௥Ճ΋Մೳɻ

  11. ࢖͍ํ

  12. ࢖͍ํ

  13. ࢖͍ํ w $PDPB1PETQPE+41BUDI w <+1&OHJOFTUBSU&OHJOF> w <+1&OHJOFFWBMVBUF4DSJQUTDSJQU> 4DSJQU

  14. ࠩ͠ସ͑Δ΋ͷΛఆٛ͢ΔKT 4DSJQU ϩʔΧϧϑΝΠϧɺωοτɺετϦϯά ಛఆͳOBNFDPOWFOUJPOͰɺ0CKFDUJWF$ޓ׵

  15. %FNP Talk is cheap. Show me the code.

  16. 3VMFEFpOF$MBTT w Ϋϥεͷϝιʔυ࠶ఆٛ defineClass("ClassName", { method: function() { ... },

    }) @implementation ClassName -(void)method { … } defineClass(classDeclaration, instanceMethods, classMethods)
  17. 3VMFΞϯμʔόʔ w ΫϥεͷεϖʔεΛࠩ͠ସ͑Δ @implementation JPTestObject - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    { } @end defineClass("JPTableViewController", { tableView_didSelectRowAtIndexPath: function(tableView, indexPath) { ... }, })
  18. 3VMF03*( w 03*(Λ෇͍ͨΒɺલͷ࣮૷ΛݺͿ @implementation JPTableViewController - (void) viewDidLoad { }

    @end defineClass("JPTableViewController", { viewDidLoad: function() { self.ORIGviewDidLoad(); }, })
  19. 3VMFTFUUFSHFUUFS w TFUUFSPSHFUUFSΛ࢖͏ @interface JPTableViewController @property (nonatomic) NSArray *data; @end

    @implementation JPTableViewController @end defineClass("JPTableViewController", { viewDidLoad: function() { var data = self.data() self.setData(data.toJS().push("JSPatch") }, })
  20. 3VMF0UIFS IUUQTHJUIVCDPNCBOH+41BUDI XJLJ6TBHFPGEFpOF$MBTT μϒϧΞϯμʔόʔ CMPDL($% TVQFS QSPUPDPM OFXQSPQFSUZNFUIPE FYUFOTJPO

  21. +41BUDI࣮ݱݪཧ ForwardInvocation Core Concept: IUUQCMPHDOCBOHOFUUFDI தࠃޠͰ͕͢ɻɻ

  22. ϦεΫ w தؒऀ߈ܸ .*5. )5514ඞཁ w ϩʔΧϧվ͟Μ҉߸Խ͢Δ w ύϑΥʔϚϯεόʔδϣϯ؅ཧΫϦςΟΧϧ όά͚ͩ

  23. 4XJGU

  24. 4XJGU w /40CKFDUͱγεςϜ"1*0, EZOBNJD EJTQBUDI  w ଞͷ͸EZOBNJDLFZXPSEΛ௥Ճඞཁ SVOUJNF ར༻͢ΔͨΊ

     w +4ʹɺDMBTT໊ͷલNPEVMF໊௥Ճඞཁ w ݁࿦ɿ࢖͑·͕͢ɺ໘౗ɻ΍Ίͯͷํ͕͍͍
  25. 5IBOLZPV '"2