Giter VIP home page Giter VIP logo

Comments (4)

andyqee avatar andyqee commented on May 8, 2024

I have got the the answer, but i don't know if it's the best practice.

while the ParentComponent can reference the ChildComponent by the property nextResponder of sender. sender.nextResponder just point the ChildComponent

- (void)someAction:(CKComponent *)sender
{
  [sender.nextResponder updateState:^id(id) {
        return newState;
    }];
}

from componentkit.

adamjernst avatar adamjernst commented on May 8, 2024

Use two different actions:

@implementation ParentComponent

+ (instancetype)new
{
  return [super newWithComponent:
          [ChildComponent
           newWithAction:@selector(someAction:)]];
}

- (void)someAction:(CKComponent *)sender
{
  // Do something
}

@end

@implementation ChildComponent
{
  CKComponentAction _action;
}

+ (instancetype)newWithAction:(CKComponentAction)action
{
  ChildComponent *c =
  [super newWithComponent:
   [CKButtonComponent
    newWithAction:@selector(buttonAction)]];
  if (c) {
    c->_action = action;
  }
  return c;
}

- (void)buttonAction
{
  CKComponentActionSend(_action, self);
}

@end

from componentkit.

leoschweizer avatar leoschweizer commented on May 8, 2024

Since I just spent some time figuring this out, I might as well share the insight: This only seems to work if the child component has a custom ComponentController implementation (which can be completely empty!). Otherwise, I get an exception:

'NSInternalInconsistencyException', reason: 'Unhandled component action myAction: following responder chain <MyComponent: 0x7feeab1e81e0> -> nil'

I can't judge if this is a bug or as designed ;)

Edit: it turns out, this is only the case if you do an updateState before calling the passed action.

from componentkit.

andyqee avatar andyqee commented on May 8, 2024

@leoschweizer It works ok for me . By the way do your child component hold it's own state? if the component has no state, but you call the [childComponent updateState]. It will crash . You can review the doc http://componentkit.org/docs/state.html

from componentkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.