How to use the inferno-mobx.inject function in inferno-mobx

To help you get started, we’ve selected a few inferno-mobx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github infernojs / inferno / packages / inferno-mobx / __tests__ / inject.spec.jsx View on Github external
it('using a custom injector is reactive', done => {
    const user = mobx.observable({ name: 'Noa' });
    const mapper = stores => ({ name: stores.user.name });
    const DisplayName = props =&gt; <h1>{props.name}</h1>;
    const User = inject(mapper)(DisplayName);
    const App = () =&gt; (
      
        
      
    );
    render(, container);

    expect(container.querySelector('h1').textContent).toBe('Noa');

    user.name = 'Veria';
    expect(container.querySelector('h1').textContent).toBe('Veria');
    done();
  });
  // TODO: fix this!
github infernojs / inferno / packages / inferno-mobx / __tests__ / generic.spec.jsx View on Github external
*/
    class TodoView extends Component {
      render() {
        const { foo } = nullthrows(this.props.apiService);
        const { baz } = nullthrows(this.props.todoService);

        return (
          <p>
            {foo}
            {baz}
          </p>
        );
      }
    }

    let Todo = inject('apiService', 'todoService')(observer(TodoView));

    // Legacy.
    Todo = observer(['apiService', 'todoService'])(TodoView);
    Todo = observer(['apiService', 'todoService'], TodoView);

    const services = {
      apiService: new ApiService(),
      todoService: new TodoService()
    };

    const A = () =&gt; (
      
        
      
    );
github infernojs / inferno / packages / inferno-mobx / __tests__ / observer.spec.jsx View on Github external
it('component should not be inject', function(done) {
    const msg = [];
    const baseWarn = console.error;
    console.error = m =&gt; msg.push(m);

    observer(
      inject('foo')(
        createClass({
          render() {
            return (
              <div>
                context:
                {this.props.foo}
              </div>
            );
          }
        })
      )
    );

    expect(msg.length).toBe(1);
    console.error = baseWarn;
    done();
github infernojs / inferno / packages / inferno-mobx / __tests__ / inject.spec.jsx View on Github external
it('overriding stores is supported', done =&gt; {
    const C = inject('foo', 'bar')(
      observer(
        createClass({
          render() {
            return (
              <div>
                context:
                {this.props.foo}
                {this.props.bar}
              </div>
            );
          }
        })
      )
    );
    const B = () =&gt; ;
    const A = createClass({
github infernojs / inferno / packages / inferno-mobx / __tests__ / inject.spec.jsx View on Github external
it('props override context', done =&gt; {
    const C = inject('foo')(
      createClass({
        render() {
          return (
            <div>
              context:
              {this.props.foo}
            </div>
          );
        }
      })
    );
    const B = () =&gt; ;
    const A = createClass({
      render: () =&gt; (
        
          <b></b>
github infernojs / inferno / packages / inferno-mobx / __tests__ / inject.spec.jsx View on Github external
it('support static hoisting, wrappedComponent and wrappedInstance', done =&gt; {
    const B = createClass({
      render() {
        this.testField = 1;
        return <div>{this.testField}</div>;
      }
    });
    B.bla = 17;
    B.bla2 = {};
    const C = inject('booh')(B);

    expect(C.wrappedComponent).toBe(B);
    expect(B.bla).toBe(17);
    expect(C.bla).toBe(17);

    let c = null;
    render( (c = i)} booh={42} /&gt;, container);
    expect(c.wrappedInstance.testField).toBe(1);
    done();
  });
github infernojs / inferno / packages / inferno-router / __tests__ / mobx-router.spec.jsx View on Github external
let showView = searchStore['query'] ? 'results' : 'default';

          return (
            <div>
              <a href="#front" id="test-btn">
                link
              </a>
              {showView === 'default' &amp;&amp; <div>default</div>}
              {showView === 'results' &amp;&amp; }
            </div>
          );
        }
      }
    );

    SearchPage = inject('searchStore')(SearchPage);

    class SearchResult extends Component {
      render() {
        return <div>results</div>;
      }
    }

    /**
     * Routing
     */
    const searchStore = new SearchStore();
    const memHistory = createMemoryHistory();

    const appRoutes = (

inferno-mobx

Official Inferno bindings for Mobx

MIT
Latest version published 10 months ago

Package Health Score

78 / 100
Full package analysis